PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] Bring data in edit view Cakephp 3

 February 17, 2022     cakephp, cakephp-3.0     No comments   

Issue

I can not get the "Contact" data displayed in the Edit form. In the Edit view, it shows me the Volunteers and People data, but not the contacts data. To bring the data, I must change "echo $ this-> Form-> input ('direccion');" by echo $ this-> Form-> input ('persona.contacto.direccion'); but by doing this the contact form is not saved. What is the solution?

In my form

echo $this->Form->input('direccion'); echo $this->Form->input('persona.nombre'); echo $this->Form->input('persona.voluntario.cv');

In my function edit controller

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

Solution

As the manual says, "By default the save() method will also save one level of associations". You're trying to save a second level of associations, so "When building forms that save nested associations, you need to define which associations should be marshalled". So, your patch statement should look more like this:

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


Answered By - Greg Schmidt
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing