免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
Yii框架權(quán)限控制
需求:公司擁有一套用戶(hù)權(quán)限系統(tǒng)。我們?cè)谛掳婵蚣苤校覀冃枰嫒葸@套用戶(hù)權(quán)限系統(tǒng)。
問(wèn)題:YII單表方式已經(jīng)滿(mǎn)足不了我們的需求,急切需要對(duì)YII進(jìn)行擴(kuò)展設(shè)計(jì),支持?jǐn)?shù)據(jù)庫(kù)分表設(shè)計(jì)
解決方法:1、新建protected/sinashowExt/JController.php文件
[php] view plaincopy
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class JController extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/column1';
/**
* @var 菜單 {@link CMenu::items}.
*/
public $menu=array();
/**
* @var 路徑設(shè)置
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs = array();
//視圖數(shù)據(jù)
public $view        = array();
//是否自動(dòng)輸出
public $autoView    = false;
//輸出頁(yè)面
public $renderPage  = '';
//頁(yè)面提示文字
public $notice  = '';
//搜索標(biāo)簽
public $searchTag   = array();
//其他代碼
public $otherHtml   = '';
//按鈕標(biāo)簽
public $buttonTag   = array();
//單位標(biāo)簽
public $unitTag     = '';
//輸出信息
public $alertText   = '';
//是否顯示外框
public $haveBorder   = true;
public function init()
{
$cookie = Yii::app()->request->getCookies();
Yii::app()->user->id  = $cookie->itemAt('SSD_user_id')->value;
Yii::app()->user->name    = $cookie->itemAt('SSD_user_nick')->value;
}
/**
* 判斷是否有指定操作的權(quán)限
*
* @param string $action
*/
public function checkPower($action)
{
return "purviewPcc::model()->checkPower('{$this->getModule()->getId()}', '{$this->getId()}', '{$action}')";
}
/**
* 檢查權(quán)限擴(kuò)展
*
* @param string $action
* @param string $contrl
* @param string $module
*/
public function checkPowerEx($action, $contrl=null, $module=null)
{
if ($contrl === null)
{
$contrl = $this->getId();
}
if ($module === null)
{
$module = $this->getModule()->getId();
}
return purviewPcc::model()->checkPower($module, $contrl, $action);
}
/**
* 權(quán)限判斷
*
*/
public function purview($module, $control, $action)
{
if (!purviewPcc::model()->checkPurview($module,$control,$action))
{
echo '沒(méi)有訪問(wèn)權(quán)限!';
Yii::app()->end();
}
}
/**
* Action操作前動(dòng)作
*
* @param unknown_type $action
* @return unknown
*/
public function beforeAction($action)
{
if($action && $this->getModule())
$this->purview($this->getModule()->getId(), $this->getId(), $action->getId());
return true;
}
/**
* Action操作后動(dòng)作
*
* @param string $action
*/
public function afterAction($action)
{
/** 是否自動(dòng)輸出 */
if ($this->autoView)
{
//默認(rèn)輸入頁(yè)面
if (empty($this->renderPage))
$this->renderPage    = $action->getId();
$this->render($this->renderPage, $this->view);
}
}
/**
* 頁(yè)面提示窗口
*
* @param string $view
* @param array $data
* @param bool $exit
*/
public function alert($msg, $href = 'javascript:history.go(-1);', $time = 0, $exit = true, $view = '//system/alert', $data = array())
{
$this->autoView  = false;
$data['msg']    = $msg;
$data['href']   = $href;
$data['time']   = $time;
$this->render($view, $data);
if ($exit)
{
Yii::app()->end();
}
}
}
使用方法:例子:新做了菜單http://localhost/index.php?r=default/site/index菜單。操作有delete、create、update
步驟:
1、向綜合后臺(tái)管理員申請(qǐng)菜單權(quán)限和菜單操作權(quán)限(110101、11010101[刪除]、11010102[新建]、11010103[修改])
2、在protected/config/purview.php 文件中為對(duì)應(yīng)的action配置權(quán)限ID
[php] view plaincopy
return array(
'default'=>array(
'site'=>array(
'index'=>110101,
'delete'=>11010101,
'create'=>11010102,
'update'=>11010103
)
)
);
3、完成以上功能,基本已經(jīng)完成了權(quán)限的配置,但是假如在用戶(hù)沒(méi)有某操作權(quán)限的時(shí)候,需要隱藏操作鏈接的時(shí)候,我們可以做一下操作
[php] view plaincopy
//表格內(nèi)容
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'columns'=>array(
'id',
'start_dt',
'end_dt',
array(
'class'=>'CButtonColumn',
'template'=>'{update} {delete}',
'updateButtonOptions'=>array(
'onclick'=>'$.fn.sinaShow.openWindow("節(jié)目修改", this.href); return false;',
),
'buttons'=>array(
'update'=>array(
'visible'=>$this->checkPower('update')
),
'delete'=>array(
'visible'=>$this->checkPower('delete')
),
)
),
)
));
在這里的visible表達(dá)式中設(shè)置調(diào)用$this->checkPower('操作名');就可以隱藏沒(méi)有權(quán)限訪問(wèn)的菜單了
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
yii使用驗(yàn)證碼
Yii PHP 框架分析(四)
Struts2教程
java 把分鐘 轉(zhuǎn)化成 天、時(shí) 、分
mysql-動(dòng)態(tài)更改數(shù)據(jù)庫(kù)連接Yii
通過(guò)幾道CTF題學(xué)習(xí)yii2框架
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服