【问题标题】:Yii accessControl does not work. accessRules()Yii 访问控制不起作用。访问规则()
【发布时间】:2013-11-29 00:40:54
【问题描述】:

我已经多次使用 accessRules(),但突然在一个新项目中它开始对我不起作用。

这就是我分配它的方式。

class DefaultController extends AppController
{

    public function filters()
    {
        return array(
            'accessControl',
        );
    }

    public function accessRules()
    {
        return array(
            array('allow',
                'actions'=>array('index'),
                'users'=>array('*'),
            ),
            array('deny',
                'users'=>array('*'),
            ),
        );
    }
    /**
     * Declares class-based actions.
     */
    public function actions()
    {
        return array(
            'list'=>'api.controllers.default.ListAction',
            'index'=>'api.controllers.default.IndexAction',
            'deviceSignUp'=>'api.controllers.default.DeviceSignUpAction'
        );
    }
}

我有一个名为 list 的操作。作为打击,

class ListAction extends RestAction
{

    public function run()
    {}
}

问题是,即使我已经为除索引之外的所有其他操作设置了拒绝。我仍然可以通过 www.mywebsite.com/default/list 查看 ListAction,这实际上应该给我一个错误,因为没有经过身份验证。我在这里缺少什么或为什么 accessControl 不起作用?

【问题讨论】:

  • “我已经为除索引之外的所有其他操作设置了拒绝” -- 你在哪里做的?

标签: php yii access-control


【解决方案1】:

@符号表示授权用户, * 表示所有用户。

使用典型的 accessControl 数组:

return array(
        array('allow',  // allow all users to some public actions
            'actions'=>array(<PUBLIC ACTIONS LIST>),
            'users' => array('*'),
        ),
        array('allow',  // allow all authorized users to some actions
            'actions'=>array(<AUTHORIZATION-NEEDED ACTIONS LIST>),
            'users' => array('@'),
        ),
        array('deny', // deny all other actions
            'users' => array('*'),
        ),              
);

【讨论】:

    猜你喜欢
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    相关资源
    最近更新 更多