即使以管理员身份登录,Yii也会收到错误403

时间:2012-08-25 07:01:13

标签: php yii

public function actionCheckout()
{
     echo "Hello World!";
}

我刚刚在控制器中创建了这个非常简单的代码,但是当我尝试在我的URL中浏览它时,它显示了这个错误:

enter image description here

即使我当前以管理员身份登录,但仍然无法访问非常简单的代码。

我将发布CRUD生成的accessRules,我不知道这是否相互关联,但当我尝试删除此行时,我已经可以访问该页面了。

public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view'),
                'users'=>array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('create','update'),
                'users'=>array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions'=>array('admin','delete'),
                'users'=>array('admin'),
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }

如果您可以看到在该代码上没有声明结帐,那么无关紧要。

您认为/是什么原因?非常感谢您的帮助和奖励!

谢谢! :)

2 个答案:

答案 0 :(得分:5)

如果您的控制器中有访问规则,则需要将此“结帐”操作添加到这些规则中。

您需要将“checkout”添加到accessRules()函数中所需的访问级别。如果每个人都可以访问它,那么您需要:

        array('allow',  // allow all users to perform 'index' and 'view' actions
            'actions'=>array('index','view', 'checkout'),
            'users'=>array('*'),
        )

或仅供管理员访问:

        array('allow',  // allow admin user access
            'actions'=>array('admin','delete','checkout'),
            'users'=>array('admin'),
        )

答案 1 :(得分:1)

你必须在一个地方'checkout'指向accessRules(我设置了所有允许的操作

public function accessRules()
{
    array('allow',  // allow all users to perform 'index', 'view' and 'checkout' actions
        'actions'=>array('index','view', 'checkout'),
        'users'=>array('*'),
    ),
    array('allow', // allow authenticated user to perform 'create', 'update' and 'checkout'actions
        'actions'=>array('create','update','checkout'),
        'users'=>array('@'),
    ),
    array('allow', // allow admin user to perform 'admin','delete' and 'checkout' actions
        'actions'=>array('admin','delete','checkout'),
        'users'=>array('admin'),
    ),
    array('deny',  // deny all users
        'users'=>array('*'),
    ),
 }