0

ifCake 2.7 フレームワークの PHP に、最初のステートメントを超えないログイン機能があります。条件は常に偽のようで、なぜ私は本当に混乱しています。リクエストを正しく実装していませんか? どんな助けでも大歓迎です。

ログイン()

function login() { 

if (!empty($this->request->data) && $this->Auth->user()) {

  // Delete all old tokens
  $this->Tour->recursive = -1;
  $this->Tour->deleteAll(array('Tour.userid' => $this->Auth->user('userid')));
  // Create a new token

  $this->Tour->create();
  $this->Tour->save(array('token' => md5(rand()), 'userid' => $this->Auth->user('userid')));
  // Update login count
  $user = $this->User->read(null, $this->Auth->user('userid'));
  $user['User']['logincount']++;
  $this->User->saveField('logincount', $user['User']['logincount']);
  // Update last login time
  $this->User->saveField('lastlogin', date('Y-m-d h:m:s'));
  echo 'doesnt work';
  if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            echo 'authLogin';
            return $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
        }

}
}
}
4

1 に答える 1

3

最初の if ステートメントを通過しません。

もちろん、&& $this->Auth->user()あなたの状態のせいではありません。ユーザーがログインしていないため、 null が返され、ブロック$this->Auth->user()に入りません。if

于 2015-10-08T14:50:38.830 に答える