cakePHP登录失败

cakePHP登录失败,php,cakephp,Php,Cakephp,我刚刚开始用cakePHP编码。我四处编码,试图写一个登录和身份验证页面 我试过这个: class AppController extends Controller { public function beforeFilter() { parent::beforeFilter(); if ($this->request->action != 'login' && !$this->Session->check

我刚刚开始用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'
            ));
        }
    }
}
我的问题是我无法登录。我总是很紧张

“您没有登录”

如果没有此代码,它可以工作,但无法保护其他页面。
myroutes.php

Router::connect('/', array('controller' => 'profiles', 'action' => 'login'));
My 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!');
    }
}

看起来您没有加载auth组件,也没有实际登录用户

您可能想在生成自己的身份验证之前考虑构建函数。

关于认证的文件

学习蛋糕认证的教程。这很简单