0

我在操作中使用此代码注册新用户:

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 在此字段中插入正确的日期?谢谢。

4

1 回答 1

3

根据 cakephp 约定,该字段应命名为created.

Cakephp 将自动填充该字段。

它写在该的底部。

更详细的文档,但对于 1.3 版本:docs

于 2012-08-02T22:28:11.090 回答