2013-07-03 71 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