-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Labels
Milestone
Description
I have this controller and edit action:
src/Controller/RecordsController
<?php
namespace App\Controller;
use App\Controller\AppController;
/**
* Edit method
*
* @param string $id
* @return void
* @throws \Cake\Network\Exception\NotFoundException
*/
public function edit($id = null) {
$record = $this->Records->get($id, [
'contain' => ['Addresses','Businesses.Businesstypes','Organizations','Persons','Telephones.Telephonetypes']
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$record = $this->Records->patchEntity($record, $this->request->data,
['atomic'=>false,'associated'=> ['Addresses','Businesses.Businesstypes','Organizations','Persons','Telephones.Telephonetypes']]
);
if ($this->Records->save($record, ['atomic'=>false, 'associated'=> ['Addresses','Businesses.Businesstypes','Organizations','Persons','Telephones.Telephonetypes']])) {
$this->Flash->success('The record has been saved.');
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error('The record could not be saved. Please, try again.');
}
}
$telephonetypes = $this->Records->Telephones->Telephonetypes->find('list');
$businesstypes = $this->Records->Businesses->Businesstypes->find('list');
$this->set(compact('record', 'users','telephonetypes', 'businesstypes'));
}The edit.ctp for the record is:
<div class="records form large-10 medium-9 columns">
<?= $this->Form->create($record) ?>
<fieldset>
<legend><?= __('Edit Record') ?></legend>
<?php
echo $this->Form->input('name');
echo $this->Form->input('url');
echo $this->Form->input('description');
echo $this->Form->input('businesses.0.businesstype_id', ['options' => $businesstypes]);
echo $this->Form->input('telephones.0.telephonetype_id', ['options' => $telephonetypes]);
echo $this->Form->input('telephones.0.telephone');
echo $this->Form->input('addresses.0.streetAddress');
echo $this->Form->input('addresses.0.addressLocality');
echo $this->Form->input('addresses.0.postalCode');
echo $this->Form->input('addresses.0.addressCountry');
echo $this->Form->input('addresses.0.description',['label'=>__('Address Description')]);
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>When I try to submit form I get this data with debug($record)
var_dump($this->request->data):
array (size=6)
'name' => string 'Midori Kocak' (length=12)
'url' => string 'http://www.mtkocak.com' (length=22)
'description' => string 'My name is Midori!' (length=18)
'businesses' =>
array (size=1)
0 =>
array (size=1)
'businesstype_id' => string '1' (length=1)
'telephones' =>
array (size=1)
0 =>
array (size=2)
'telephonetype_id' => string '1' (length=1)
'telephone' => string '+420775259871' (length=13)
'addresses' =>
array (size=1)
0 =>
array (size=5)
'streetAddress' => string 'Parizska 5' (length=10)
'addressLocality' => string 'Prague' (length=6)
'postalCode' => string '110 00' (length=6)
'addressCountry' => string 'Czech Republic' (length=14)
'description' => string 'Home Office' (length=11)If I do validate->false in save() method, message says it is updated, if not, I get cannot saved error.