cakephp 3.x data not saving when Saving data into 2 tables with has many relation -
i have 2 tables clients , branches branches has field client_id relation between them client hasmany branches , branch belongs user, have following code in clients/add.ctp view file
<?php echo $this->form->create($client); echo $this->form->input('name'); echo $this->form->input('branch.0.branch_name'); echo $this->form->input('branch.0.email'); echo $this->form->input('profile_link'); ?> , controller code isas follow <?php public function add() { $client = $this->clients->newentity(); if ($this->request->is('post')) { $client = $this->clients->patchentity($client, $this->request->data, [ 'associated' => ['branches'] ]); if($this->clients->save($client)) { $this->flash->success(__('data has been saved.')); } else { $this->flash->error(__('the data not saved. please, try again.')); } } ?>
but data saved in client table not in branch table please tell me should id or whats error sorry bad english
if client hashany
branches should do
echo $this->form->input('branches.0.branch_name'); echo $this->form->input('branches.0.email');
read manual it
Comments
Post a Comment