我遇到了 CakePHP 的 saveAll() 问题,我希望有人能解释一下。
我有一个表格,它收集要为两个模型保存的信息......人员和查询。我相信数据发送正确,但它根本没有保存查询数据。它返回一个验证错误,但在 Inquiry 模型中没有设置验证,如果我从 People 控制器中删除 'deep' => true ,它会很好地保存这些字段。
它发布的数据
Array
(
[Person] => Array
(
[first_name] => Test
[middle_name] =>
[last_name] => User
[gender] => M
[date_of_birth] => Array
(
[month] => 02
[day] => 07
[year] => 1994
)
[address] => 1234 Main St
[address_apt] =>
[address_city] => Somewhere
[address_state] => OH
[address_zip] => 304982
[address_country] => US
[phone_cell] => (555) 555-5555
[permission_to_text] => 1
[phone_home] => (555) 555-5556
[email_address] => test@user.com
[preferred_contact] => text_cell
[Inquiry] => Array
(
[admit_type] => FR
[admit_term] => FA2014
[parent_first_name] => Mom
[parent_last_name] => User
[parent_email] => mom@user.com
[hs_name] => Columbus Downtown High School
[hs_ceeb_id] => 365210
[hs_homeschooled] => 0
[hs_grad_year] => Array
(
[year] => 2014
)
[coll_name] =>
[coll_ceeb_id] =>
[coll_major] =>
[coll_year] =>
[admit_major] => 1
[admit_minor] => 4
)
[social_facebook] =>
)
)
发布后 $this->Person->validationErrors 的值
Array
(
[Inquiry] => Array
(
[hs_homeschooled] => Array
(
)
[coll_name] => Array
(
)
[coll_ceeb_id] => Array
(
)
[coll_major] => Array
(
)
[coll_year] => Array
(
)
)
)
型号 - 询价
<?php
class Inquiry extends AppModel {
public $belongsTo = array('Person');
}
控制器
<?php
class PeopleController extends AppController {
public $helpers = array('Html', 'Form', 'Country', 'State', 'Major', 'Minor', 'Term');
public function index() {
if ($this->request->is('post')) {
$this->Person->create();
if ($this->Person->saveAll($this->request->data, array('deep' => true))) {
print_r($this->request->data);
$this->Session->setFlash(__('Your post has been saved.'));
return $this->redirect(array('action' => 'index'));
}
print_r($errors = $this->Person->validationErrors);
$this->set('errors', $errors = $this->Person->validationErrors);
$this->Session->setFlash(__('Unable to add.'));
}
}
}