2013-07-03 38 views
0

我正在Cakephp 2.x上工作..我在我的用户表中有一个名为“logindate”的字段..我设置日期但不知道为什么它不会将当前第一次登录系统的用户的日期保存到用户表中。这里是我的UsersController代码。当用户第一次登录到系统时设置用户日期Cakephp

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分贝的数据类型为VARCHAR和hardcorded这样

 $this->request->data['User']['lastLogin'] = "hello"; 

值它仍然没有工作......不知道为什么它不节能分贝对用户ID

回答

0

但不知道为什么它不保存日期到用户表

您未在登录功能的任何位置调用保存。

+0

:oooooooopss:p – hellosheikh