CakePHP的isAuthorized()不会被调用 [英] cakephp isAuthorized() not being called

查看:363
本文介绍了CakePHP的isAuthorized()不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用isAuthorized()方法做一个管理标志的检查,但功能似乎永远不会被调用。甚至当我开启该功能总是返回false,它允许任何用户。这似乎只是它不被调用。

我需要做的东西比设定更$这个 - > Auth->授权=控制器?

从/app/app_controller.php

 类AppController的扩展控制器
{变量$ =组件阵列('验证');功能beforeFilter()
{
    $这个 - > Auth->在loginAction =阵列(控制器= GT;'用户','行动'=>'登录');
    $这个 - > Auth-> loginRedirect =阵列(控制器= GT;'网页','显示'=>'家');
    $这个 - > Auth-> logoutRedirect ='/';
    $这个 - > Auth->授权=控制器;
    $这 - > Auth-> userScope =阵列('User.active'=大于1);
}功能isAuthorized()
{
    如果(strpos($这个 - >!行动ADMIN_)= FALSE)
    {
    如果($这个 - > Auth->用户('isAdmin')=='0')
    {
    返回false;
    }
    }
    返回true;
}
}


解决方案

您应该检查,如果你在你的其他控制器覆盖您的验证设置。

首先,以验证 isAuthorized()被调用,可以尝试在一个简单的调试($本);死;它

如果它是不会死的,你可能覆盖它在其他控制器(您缺少父:: isAuthorized()调用)。

如果它不是,那么你很可能这样做,用同样的事 beforeFilter()

I am trying to use the isAuthorized() method to do a check for an admin flag, but the function never seems to be called. Even when I set the function to always return false, it allows any user. It just seems like it isn't being called.

Do I need to do something more than setting $this->Auth->authorize = 'controller' ?

from /app/app_controller.php

class AppController extends Controller
{

var $components = array('Auth');

function beforeFilter()
{
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->loginRedirect = array('controller' => 'pages', 'display' => 'home');
    $this->Auth->logoutRedirect = '/';
    $this->Auth->authorize = 'controller';
    $this->Auth->userScope = array('User.active' => 1);
}

function isAuthorized()
{
    if (strpos($this->action, "admin_") != false)
    {
    	if ($this->Auth->user('isAdmin') == '0')
    	{
    		return false;
    	}
    }
    return true;
}
}

解决方案

You should check if you're overriding your Auth settings in your other controller.

First, to verify that isAuthorized() is being called, try putting a simple debug($this); die; in it.

If it is not dying, you're probably overriding it in some other controller (you're missing the parent::isAuthorized() call).

If it's not that, then you're probably doing that same thing with beforeFilter().

这篇关于CakePHP的isAuthorized()不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆