如何在CakePHP 2.0中使用身份验证

如何在CakePHP 2.0中使用身份验证,cakephp,authentication,Cakephp,Authentication,基本上,我有一个控制器/操作-用户/登录,用户在其中登录,还有一个控制器图像/添加,用户可以在其中上传图像 我向上看了看,但对于如何执行以下操作,我有点困惑: 我希望用户能够通过user/login登录,并被重定向到images/add。我希望只有用户登录后才能访问此页面 现在我没有使用Auth,但是我有这个 UserController.php function login() { if(empty($this->data) == false)

基本上,我有一个控制器/操作-用户/登录,用户在其中登录,还有一个控制器图像/添加,用户可以在其中上传图像

我向上看了看,但对于如何执行以下操作,我有点困惑:

我希望用户能够通过user/login登录,并被重定向到images/add。我希望只有用户登录后才能访问此页面

现在我没有使用Auth,但是我有这个 UserController.php

   function login() 
    {   
        if(empty($this->data) == false) 
        {   
            if(($user = $this->User->validateLogin($this->data['User'])) == true) 
            {   
                $this->Session->write('User', $user); 
                $this->Session->setFlash('You\'ve successfully logged in.'); 
                $this->redirect('/images/add'); 
            }   
            else 
            {   
                $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.'); 
            }   
        }   
    }   
User.php模型

function login() 
{   
    if(empty($this->data) == false) 
    {   
        if(($user = $this->User->validateLogin($this->data['User'])) == true) 
        {   
            $this->Session->write('User', $user); 
            $this->Session->setFlash('You\'ve successfully logged in.'); 
            $this->redirect('/images/add'); 
        }   
        else 
        {   
            $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.'); 
        }   
    }   
}   
如何使用身份验证而不是基于会话的检查?我是否仍然需要在模型中使用_validateLogin函数来检查用户是否在DB中?另外,我将如何限制已登录用户可以访问的图像/添加