我在操作中使用此代码注册新用户:
public function register() {
$this->set('title_for_layout', 'Register');
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash('Your account has been created. You may now login with your username and password.', 'default', array('class' => 'success-flash'));
$this->redirect(array('action' => 'register'));
} else {
$this->Session->setFlash('There was an error creating your account.', 'default', array('class' => 'error-flash'));
}
}
}
但是,我的数据库用户表中的regisered
字段始终是0000-00-00 00:00:00
。如何让Cake在此字段中插入正确的日期?谢谢
根据cakephp惯例,字段应命名为created
。
Cakephp将自动填充该字段。
它写在那一段的底部。
更详细的文档,但适用于1.3版本:docs。