simpman 2011-10-12 11:50:00 3308次浏览 1条回复 0 0 0
<?php
/*
 * Created on 2011-10-12
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class AuthController extends CController{
    /**
    * @return array action filters
    */
    public function filters()
    {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    /**
    * Specifies the access control rules.
    * This method is used by the 'accessControl' filter.
    * @return array access control rules
    */
    public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('show'),
                'users'=>array('*')
            ),
        );
    }

    public function actionTest(){
        $auth=Yii::app()->authManager;
        $auth->createOperation("postop",'postpost');
        $auth->createTask("postta","posts");
        $auth->createRole("postro","post");
        $auth->addItemChild("postro","postop");
        $auth->assign("postro",'demo');
    }
    public function actionShow(){
        //echo Yii::app()->user->isGuest;
        if(Yii::app()->user->checkAccess("postop")){
            echo 'Yes';
        }else{
            echo 'No';
        }
    }
}
?>

结果还是打印 No,蛋疼。 而且在表中有记录:

authassignment postop	demo	NULL	N;

   authitem:    postop	0	postpost	NULL	N;
			postro	2	post	NULL	N;
			postta	1	posts	NULL	N;
您需要登录后才可以回复。登录 | 立即注册