【问题标题】:Bring data in edit view Cakephp 3将数据带入编辑视图 Cakephp 3
【发布时间】:2019-03-02 14:14:35
【问题描述】:

我无法获得“编辑”表单中显示的“联系人”数据。在编辑视图中,它显示志愿者和人员数据,但不显示联系人数据。要带数据,我必须改“echo $this->Form->input('direccion');”通过 echo $ this-> Form-> input ('persona.contacto.direction');但这样做不会保存联系表格。解决办法是什么?

以我的形式

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.'));
    }

【问题讨论】:

    标签: cakephp cakephp-3.0


    【解决方案1】:

    正如the manual 所说,“默认情况下,save() 方法还将保存一级关联”。您正在尝试保存第二级关联,因此“在构建保存嵌套关联的表单时,您需要定义应该编组的关联”。所以,你的补丁语句应该看起来更像这样:

    $particulare = $this->Particulares->patchEntity($particulare, $this->request->getData(),
        'associated' => ['Voluntarios', 'Personas.Contactos']
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多