I have Yii setup with basic Access Control Filter. I have no plans to use the RBAC, but I can’t find a way to know whether they have access to a page or not. Let me give an example:
I have a cmenu that takes you different places.
Now if they don’t have access to that page, I don’t want to show the menu item. They will get a Access Denied page if they visit the page, which is good, but I don’t want to show the link in the first place. Is there a simple way to check if they have access to a page.
Maybe you can instantiate [font="Courier New"]CAccessControlFilter[/font] with the array returned from [font="Courier New"]CController::accessRules()[/font] (use $this inside your layout) and then call [font="Courier New"]CAccessControlFilter::isUserAllowed($user,$controller,$action,$ip,$verb)[/font].
Well you pushed me in the right direction, but it looks like it is not going to be able to scale easily. I would need to set the rules from a different controller than I currently am in, so it doesn’t look possible.
$this->widget('zii.widgets.CMenu', array(
'items'=>array(
// Important: you need to specify url as 'controller/action',
// not just as 'controller' even if default acion is used.
array('label'=>'Home', 'url'=>array('site/index')),
// 'Products' menu item will be selected no matter which tag parameter value is since it's not specified.
array('label'=>'Products', 'url'=>array('product/index'), 'items'=>array(
array('label'=>'New Arrivals', 'url'=>array('product/new', 'tag'=>'new')),
array('label'=>'Most Popular', 'url'=>array('product/index', 'tag'=>'popular')),
)),
array('label'=>'Login', 'url'=>array('site/login'), 'visible'=>Yii::app()->user->isGuest),
),
));