我正在使用 Cakephp 2.x .. 我的用户表中有一个名为“logindate”的字段.. 我正在设置一个日期。但不知道为什么它没有将日期保存到用户表中针对当前正在使用的用户第一次登录系统..这是我的UsersController代码。
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('index');
$this->Security->requireSecure('login');// for security
$this->Auth->authenticate = array(
'Authenticate.Cookie' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'userModel' => 'User',
),
'Authenticate.MultiColumn' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'columns' => array('email', 'mobileNo'),
'userModel' => 'User',
)
);
}
public function index(){
$this->layout='logindefault';
if (!$this->Auth->login() || !$this->Auth->loggedIn()) {
$this->redirect('/users/login');
}else {
$this->redirect('/users/dashboard');
}
}
public function login() {
$this->layout='logindefault';
$this->set('title_for_layout', 'Account Login');
if ($this->Auth->login() || $this->Auth->loggedIn()) {
$this->redirect(array('controller' => 'Userinfo', 'action' => 'gettingstarted'));
//$this->redirect('/users/dashboard');
}else{
if ($this->request->is('post')) {
//here i am saving the date
$this->request->data['User']['lastLogin'] = date('y-m-d h:i:s');
$mobileNo=$this->request->data['User']['email'];
$pos = strpos($mobileNo,'@');
if($pos){
}else {
$mystr=substr($mobileNo,0,1);
if ($mystr!='+'){
$mobileNo = '+'.$mobileNo;
}
}
$this->request->data['User']['email'] = $mobileNo;
if ($this->Auth->login() || $this->Auth->loggedIn() ) {
if ($this->Session->check('Auth.User')){
$this->_setCookie($this->Auth->user('idUser'));
$this->redirect(array('controller' => 'Userinfo', 'action' => 'gettingstarted'));
}
}else {
$this->Session->setFlash('Incorrect Email/Password Combination');
}
}
}
}
为了测试,我将lastLogin的 db 中的数据类型更改为varchar并将值硬编码为这样
$this->request->data['User']['lastLogin'] = "hello";
仍然没有工作......不知道为什么它没有根据用户ID保存到数据库中