我目前正在使用 Auth 组件登录。每当用户登录我的网站时,我想更新我的用户表中的 last_login 字段。
我在用户控制器中的登录功能我有 -
public function login() {
$this->layout = 'main';
if ($this->request->is('post')) {
if($this->Auth->login()) {
$this->redirect(array('controller'=>'pages','action'=>'dashboard')); // after login , redirect on dahsboard
}
$this->Session->setFlash(__('Your username or password was incorrect.'));
}
$this->redirect(Router::url('/', true)); // there is no login.ctp file so it always redirect on home
}
在应用程序控制器中我有
class AppController extends Controller {
public $components = array(
'Auth',
'Session',
);
function beforeFilter() {
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->logoutRedirect = array(
'controller' => 'pages',
'action' => 'display','home'
);
}