我在这个问题上苦苦挣扎。
我的模型代码
class User extends AppModel {
App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
$validate = array();
public function beforeSave($options = array()) {
parent::beforeSave();
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new SimplePasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash(
$this->data[$this->alias]['password']
);
}
return true;
}
}
控制器的保存方法
public function register(){
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(
__('registration is successfully completed. you can login now.'),
'success',
array(),
'auth'
);
return $this->redirect(array('action' => 'login'));
}
$this->Session->setFlash(
__('The user could not be saved. Please, try again.'),
'error'
);
}
$this->layout = false;
}
谢谢。
答案 0 :(得分:0)
我对此进行了排序,我的文件名不正确。