Mycakephp version is 2.1.1.
i am trying to save the associated model manually using saveAll() function
Model
- Employee HasOne Address
- Employee Belongs to Department
so table
employees(first_name,last_name,age,sex,department_id)
addresses(first_line,second_line,city,state,employee_id)
now employee creation add.ctp has a form which receives input for employee and address
i know
$this->Employee->saveAll($this->request->data);
this will save the models but
i want to save the association manually
i was going through the official cakephp document here and i have tried something like this
$this->Employee->saveAll($data, array(
'fieldList' => array(
'Employee' => array('first_name','last_name','age','sex','department_id'),
'Department' => array('first_line', 'second_line','city','state','employee_id')
)
));
it is not working , and throws following errors
Notice (8): Undefined variable: data [APP\Controller\EmployeesController.php, line 118]
Warning (2): array_keys() expects parameter 1 to be array, null given [CORE\Cake\Model\Model.php, line 1996]
i am cakephp beginner. please help me.
$this->request->data: Array
(
[Employee] => Array
(
[first_name] => Jack
[last_name] => Robert
[age] => 32
[sex] => 0
[Department] => Development
)
[Address] => Array
(
[first_line] => HSR Layout
[second_line] => 1st Cross
[city] => Najem
[state] => Barel
)
[Department] => Array
(
[id] => 3
)
)
add()
method? Where you define$data
? – Paulo Rodrigues$data
, you should use$this->request->data
, so you get the data of your form. – Paulo Rodrigues