本文实例讲述了yii权限控制的方法。分享给大家供大家参考,具体如下:
这里摘录以下3种:
1. 通过accessControl:
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 authenticated users to access all actions
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
2. 通过插件(如:right)
西安网上购物网店系统的主要亮点:(1)商品的分类更加细化和明朗,可以三级分类,价格可以多层次\多级别,按照后台设置的,吸引会员加入。(2)会员和非会员购物并存,订单直接支付和会员帐户支付并存,电话支付与网上支付多种支付方式。(3)自定义商品扩展属性,多种扩展属性定义模式,强大的商品管理功能,多重分类功能(4)灵活的会员积分系统,灵活的会员权限控制,模版丰富多彩,模版代码分离,方便修改模版(5)支付
0
public function filters()
{
return array(
'rights',
);
}
3. 混合模式:
/**
* @return array action filters
*/
public function filters()
{
return array(
'updateOwn + update', // Apply this filter only for the update action.
'rights',
);
}
/**
* Filter method for checking whether the currently logged in user
* is the author of the post being accessed.
*/
public function filterUpdateOwn($filterChain)
{
$post=$this->loadModel();
// Remove the 'rights' filter if the user is updating an own post
// and has the permission to do so.
if(Yii::app()->user->checkAccess('PostUpdateOwn', array('userid'=>$post->author_id)))
$filterChain->removeAt(1);
$filterChain->run();
}
如果有权限的基础上,开放某些动作的权限,可以通过allowedActions:
public function allowedActions()
{
return 'autocomplate,autocomplate2';
}
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号