0
在cakephp 2中,我有一个表单为公司和用户表创建一个新记录。cakephp没有哈希模型中的密码
我的问题是,它保存到这两个表,但在Umuser表中它不散列密码或ID密钥。它似乎根本不称任何Umuser模型。这是一个保存之前,它不会这样。
public function beforeSave() {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
Umuser处于puging/Usermin/Models目录中。
公司控制器来保存数据:
public function add() {
if ($this->request->is('post')) {
$this->Company->create();
if ($this->Company->saveAll($this->request->data, array('validate'=>'first'))) { // Should ensure both sets of model data get validated
$this->Session->setFlash(__('The company has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The company could not be saved. Please, try again.'));
}
}
}
看不出为什么它保存数据,但绕过Umuser模型来做到这一点。
关联这两个型号? – entropid
我的提示:把这些东西放在一个集中的位置,以保持代码干燥。一种行为是在模型层面上做到这一点的一种好方法:http://www.dereuromark.de/2011/08/25/working-with-passwords-in-cakephp/ – mark
是的模型是相关的。 umuser表有一个名为company_id的字段。它确实保存了数据,而不是在beforesave中保存散列 –