Функция входа в CakeStack Overflow

У меня есть функция входа в PHP на основе торта 2.7, который не сможет пройти первый if заявление. Условное, кажется, всегда ложно, и я действительно смущен, почему. Я правильно не выполняю запрос? Любая помощь будет принята с благодарностью.

Авторизоваться()

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');
}

}
}
}

0

Решение

это не пройдет мимо первого оператора if.

Конечно, это не из-за && $this->Auth->user() состояние у вас есть. Поскольку пользователь не авторизован $this->Auth->user() вернет ноль и не войдет в if блок.

3

Другие решения

Других решений пока нет …