Mycakephp 버전은 2.1.1입니다.Cakephp 2.1 관련 객체 수동 저장
내가 수동으로 시려면를 사용하여 관련 모델을 저장하려고
모델
- 직원 hasOne의 주소
- 직원이 부서 에 너무
테이블
속한다() 함수employees(first_name,last_name,age,sex,department_id)
addresses(first_line,second_line,city,state,employee_id)
이제 직원 생성 add.ctp 직원 및 주소 입력을받는 형태
은 내가
$this->Employee->saveAll($this->request->data);
이이 모델을 저장 알고있다하지만
내가 수동으로
나는 공식 cakephp 문서 here을 통해 가고 있었고 나는 이것과 비슷한 것을 시도했다.
$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')
)
));
는 작업 및 발생하지 않는 다음과 같은 오류가
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]
내가 CakePHP의 초보자입니다. 도와주세요.
$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()'메소드에서 더 많은 것을 보여줄 수 있습니까? '$ data'를 정의하는 곳 은요? –
$ data를 정의하는 법을 말해 줄 수 있습니까? 그것에 대해서는 전혀 모르겠습니다. – maaz
'$ data'를 정의하지 않으면'$ this-> request-> data'를 사용해야합니다. 그러면 폼의 데이터를 얻을 수 있습니다 . –