med*_*oix 3 php datetime controller cakephp save
我在我的控制器中有bellow登录功能,我试图将登录日期/时间保存到字段last_login下的用户数据库表中,该字段是DATETIME字段,登录工作正常,但该字段永远不会被填充..任何关于什么的想法停止这个或如何解决应该输出什么?
public function login() {
$this->layout = 'login';
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->User->id = $this->Auth->user('id'); // target correct record
$this->User->saveField('last_login', date(DATE_ATOM)); // save login time
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Invalid username or password, try again', 'default', array('class' => 'warning'));
}
}
Run Code Online (Sandbox Code Playgroud)
如果db中的last_login字段设置为DATETIMEthen,则需要执行以下操作:
$this->User->saveField('last_login', date("Y-m-d H:i:s"));
Run Code Online (Sandbox Code Playgroud)
作为DATE_ATOM回报类似2012-08-15T15:52:01+00:00,所以它不会得到插入尝试禁用AuthComponent :: autoRedirect,像
public $components = array(
'Auth' => array(
......
'autoRedirect' => false //set to false to disable auto redirect
),
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9761 次 |
| 最近记录: |