【发布时间】:2017-01-04 13:52:00
【问题描述】:
我已经编写了一个基本的登录脚本,现在需要更新存储在 auth 组件中的数据,然后将其保存到数据库中,这就是我目前所拥有的;
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
$this->Auth->user()->last_activity = date("Y-m-d");
$this->Users->save($this->Auth->user());
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Email or password is incorrect, please try again.'));
}
}
我尝试了几种不同的变体,但都无法奏效。有什么想法吗?
【问题讨论】:
-
该代码肯定会触发错误,因为
AuthComponent::user()的返回值不是一个对象,而是一个数组。每当收到错误时,请将它们包含在您的问题中,包括完整的堆栈跟踪(最好从日志中以正确可读的方式复制),即使问题对于熟悉 CakePHP 的人来说可能很明显!
标签: php cakephp-3.0