2013-06-28 2 views
1

Я только начинаю кодирование с помощью cakePHP. Я закодировал и попытался написать страницу входа и аутентификации.
Я попытался это:Ошибка входа в cakePHP

class AppController extends Controller 
{ 
    public function beforeFilter() 
    { 
     parent::beforeFilter(); 
     if ($this->request->action != 'login' && !$this->Session->check('profile')) 
     { 
      $this->Session->setFlash('You are not logged in'); 
      $this->redirect(array(
       'controller' => 'profiles', 
       'action' => 'login' 
      )); 
     } 
    } 
} 

Моя проблема заключается в том, что я не могу войти. Я всегда получаю

«Вы не вошли в систему» ​​

Без этого кода, он работает, но не Протек другие страницы.
Моего routes.php

Router::connect('/', array('controller' => 'profiles', 'action' => 'login')); 

Мой ProfilesController.php

public function login() 
{ 
    if ($this->request->is('post')) 
    { 
     $profile = $this->Profile->find('first', array(
      'conditions' => array(
       'name' => $this->request->data('Profile.name'), 
       'password' => $this->request->data('Profile.password') 
      ) 
     )); 
     if ($profile) 
     { 
      $this->Session->write('Profile',$profile); 
      $this->redirect(array('controller' => 'Projects', 
       'action' => 'index')); 
     } 
     $this->Session->setFlash('Profile and Password does not match!'); 
    } 
} 

ответ

3

Похоже, что вы не загружаете компонент аутентификации и вы на самом деле не войти в пользователе.

Возможно, вы захотите рассмотреть встроенные функции аутентификации, прежде чем пытаться сделать свой собственный.

Документация по аутентификации.

http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

Учебник, чтобы узнать о подлинности Cake. Это довольно просто.

http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html

Смежные вопросы