This page explanation:
You can save the edited information.
※Click the Update button to receive an alert.
※Click “OK” on the alert to update data.
This page function:
Save(edited information)
① Controller
Controller:/app/controller/customerController.php
<?php
class customer{
//~~~
public function action_update($targetId){ //updated function
//Get POST data
$first_name = isset($_POST['first_name']) ?? $_POST['first_name'] : '';
$last_name = isset($_POST['last_name']) ?? $_POST['last_name'] : '';
$birthday = isset($_POST['birthday']) ?? $_POST['birthday'] : '';
$gender = isset($_POST['gender']) ?? $_POST['gender'] : '';
$blood = isset($_POST['blood']) ?? $_POST['blood'] : '';
$comment = isset($_POST['comment']) ?? $_POST['comment'] : '';
//Retrieve one data from the database
$custmanageObj = ORM::for_table(customer)->where('id', (int)$targetId)->find_one();
$custmanageObj->first_name = $first_name;
$custmanageObj->last_name = $last_name;
$custmanageObj->birthday = $birthday;
$custmanageObj->gender = $gender;
$custmanageObj->blood = $blood;
$custmanageObj->comment= $comment;
//save do
$custmanageObj->save();
//~~~
redirectUrl('customer'); //class “customer” to redirect.
}
//~~~
}
?>
② View
View:/app/view/customer_edit.php
<!--~~~-->
<form method='post' action=''<?= SYSTEM_DIR . '/customer/update/'.$targetId; ?>''>
<!--↑The "action=..." specifies the URL to which data is sent when the submit button is pressed.-->
<button type="button" class="btn btn-success " id="update-btn">更新</button>
<button type="button" class="btn btn-danger" id="delete-btn" >削除</button>
<table>
<!--~~~-->
<input type='text' name='last_name' value='<?php echo $last_name; ?>'>
<input type='text' name='first_name' value='<?php echo $first_name; ?>'>
<input type='text' name='birthday' value='<?php echo $birthday; ?>'>
<input type='text' name='gender' value='<?php echo $gender; ?>'>
<input type='text' name='blood' value='<?php echo $blood; ?>'>
<input type='text' name='comment' value='<?php echo $comment; ?>'>
<!--~~~-->
</table>
</form>
<!--~~~-->
