Farman Ullah Marwat
Farman Ullah Marwat

Reputation: 19

cakephp pre populate multiple multiple forms in single view

I have one problem with cakephp. I searched the whole site but do not find a proper solution.

So first let see. Pre populating form works best with form helper:

$this->request->data = $this->Model->find();

The above code populates the form but what if we have two forms with two models name?

 $this->Form->create('Basic');

and

$this->Form->create('Personal');

on the view of Profile

class ProfileController extends Appcontroller{
   public function index(){

       $this->request->data = $this->Basic->find();
       $this->request->data = $this->Personal->find();
    }

}

This code pre fill the second form not the first and if I remove the second line it fills the first form So any solution to pre populate multiple forms in a single view?

Upvotes: 0

Views: 89

Answers (1)

mark
mark

Reputation: 21743

PHP is not magic. You need to either merge the data before-hand, or assign it to subkeys:

$basic = $this->Basic->find('first');
$personal = $this->Personal->find('first');

$this->request->data['Basic'] = $basic['Basic'];
$this->request->data['Personal'] = $personal['Personal'];

would work

Upvotes: 1

Related Questions