Make sure to process registration updates in one file.
Basically, one page is used to write the registration and editing pages in the same file.
This is to reduce the amount of code to be written.
view
Skip registration and editing to the same method.
<form action="<?=SYSTEM_DIR.'/customer/create/'.$targetId?>" method="post"></form>
controller
Registration and updating are handled in the same method.
Separate registration from update based on the presence or absence of data.
class customer{
public function action_index() {
include_once(dirname(__FILE__) . "/../view/customer_list.php");
}
public function action_create($targetId) {
$custmanageObj = ORM::for_table('customer')->where('id', $targetId)->where('delete_flg', 0)->find_one();
//If there is no data
if(!$custmanageObj){
$custmanageObj = ORM::for_table('customer')->create();
$custmanageObj->created_at = date("Y-m-d H:i:s");
}else{
$custmanageObj->updated_at = date("Y-m-d H:i:s");
}
$custmanageObj->user_name= 'tarou';
$custmanageObj->save();
redirectUrl('customer');//Transition to the list
}
}