【问题标题】:Authorization adapter was not found in cakePHPcakePHP 中未找到授权适配器
【发布时间】:2012-04-17 02:44:09
【问题描述】:

我正在尝试将我的代码从本地移动到服务器 当我尝试登录应用程序时

Here is my AppController
class AppController extends Controller{
    /*  Determines what logged-in users access to */
    var $components = array('Auth','Session');

    public function isAuthorized($user){
        return true;
    }

    public function beforeFilter(){
        $userdetails = array();
        $this->Auth->autoRedirect = false;
        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'matches', 'action' => 'index');
        $this->Auth->authorize = 'controller';
        $this->Auth->authError= 'You need permissions to access this page';
        $this->Auth->allow('users');
        $this->set('Auth',$this->Auth);
        $userdetails = $this->Auth->user();
        $this->set('myUser', $userdetails['username']);
        $this->set('myRole', $userdetails['user_role_id']);
        $this->set('pStatus', $userdetails['password_status']);
    }
}


Here is my Login Action in UsersController
public function login(){
        $this->Auth->autoRedirect = false;
        $id = $this->Auth->user('id');
        if(empty($id)){
            if($this->request->is('post')){
                if($this->Auth->login()){
                    $this->redirect($this->Auth->redirect());   
                }else{
                    $this->Session->setFlash('Invalid Username or password');
                }
            }
        }else{
            $this->redirect(array('action'=>'index'));
        }   
    }

感谢您的帮助

【问题讨论】:

    标签: authentication cakephp-2.0


    【解决方案1】:

    beforeFilter 中授权控制器的部分应正确大写:

    所以:

    $this->Auth->authorize = 'Controller';

    代替:

    $this->Auth->authorize = 'controller';

    该特定语句试图找到controllerAuthorize.php,并且应该寻找ControllerAuthorize.php。这在 Windows 上不会导致问题,但在 Unix 系统上会出现问题。

    【讨论】:

    • 这句老话“魔鬼在细节中”似乎仍然是正确的。不客气。 ;)
    • 它在 Mac OS X 上也没有通知。只是说... ^^
    猜你喜欢
    • 2012-08-07
    • 2013-10-15
    • 2023-03-25
    • 2013-05-31
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多