在编辑视图 Cakephp 3 中引入数据
Bring data in edit view Cakephp 3
我无法获取编辑表单中显示的 "Contact" 数据。在编辑视图中,它向我显示了志愿者和人员数据,但没有显示联系人数据。要带数据,我必须通过 echo $ this-> Form-> input ('persona.contacto.direccion'); 更改 "echo $ this-> Form-> input ('direccion');";但是这样做不会保存联系表。解决方法是什么?
在我的表格中
echo $this->Form->input('direccion'); echo $this->Form->input('persona.nombre'); echo $this->Form->input('persona.voluntario.cv');
在我的函数中编辑控制器
$particulare = $this->Particulares->get($id, [
'contain' => ['Voluntarios','Beneficiarios','Personas'=>['Contactos'=>['Paises','Provincias','Localidades']]]
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$particulare = $this->Particulares->patchEntity($particulare, $this->request->getData());
if ($this->Particulares->save($particulare)) {
$this->Flash->success(__('Éxito! Los cambios han sido guardados correctamente'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Los cambios no pudieron ser guardados. Por favor, inténtelo de nuevo.'));
}
正如the manual所说,"By default the save() method will also save one level of associations"。您正在尝试保存二级关联,因此 "When building forms that save nested associations, you need to define which associations should be marshalled"。所以,你的补丁声明应该更像这样:
$particulare = $this->Particulares->patchEntity($particulare, $this->request->getData(),
'associated' => ['Voluntarios', 'Personas.Contactos']
);
我无法获取编辑表单中显示的 "Contact" 数据。在编辑视图中,它向我显示了志愿者和人员数据,但没有显示联系人数据。要带数据,我必须通过 echo $ this-> Form-> input ('persona.contacto.direccion'); 更改 "echo $ this-> Form-> input ('direccion');";但是这样做不会保存联系表。解决方法是什么?
在我的表格中
echo $this->Form->input('direccion'); echo $this->Form->input('persona.nombre'); echo $this->Form->input('persona.voluntario.cv');
在我的函数中编辑控制器
$particulare = $this->Particulares->get($id, [
'contain' => ['Voluntarios','Beneficiarios','Personas'=>['Contactos'=>['Paises','Provincias','Localidades']]]
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$particulare = $this->Particulares->patchEntity($particulare, $this->request->getData());
if ($this->Particulares->save($particulare)) {
$this->Flash->success(__('Éxito! Los cambios han sido guardados correctamente'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Los cambios no pudieron ser guardados. Por favor, inténtelo de nuevo.'));
}
正如the manual所说,"By default the save() method will also save one level of associations"。您正在尝试保存二级关联,因此 "When building forms that save nested associations, you need to define which associations should be marshalled"。所以,你的补丁声明应该更像这样:
$particulare = $this->Particulares->patchEntity($particulare, $this->request->getData(),
'associated' => ['Voluntarios', 'Personas.Contactos']
);