Check Access Rules


I have a question on access rules. I have the following the access rules:

public function accessRules() {

    return array(


           // Allow authenticated user to perform 'index' and 'view' actions


           'actions' => array('index', 'view'),

           'users' => array('@'),



            // Allow admin user to perform 'admin', 'create', 'update' and 'delete' actions


            'actions' => array('admin', 'create', 'update', 'delete'),

            'users' => array('admin'),



           // Deny all users


           'users' => array('*'),




I need to add a link ‘create’ only user ‘admin’. Is there any function to check if the user logged in can access the action ‘create’?

not quite sure if I understand your question but you can check if the logged in user is admin with Yii::app()->user->username == ‘admin’; for example

Hi Bettor,

So I solved it but I wanted to know if there is a function for this, because if I have a list of users that define the function ‘accessRules’, it would be good to check as defined in the function ‘accessRules’.

Sorry if I do not write well, I do not speak English.

hello German Scarel…

you can create a link in if condition

if(Yii::app()->user->username == ‘admin’){



if(Yii::app()->user->id == ‘1’ && Yii::app()->user->username == ‘admin’)



in protected/views/site/index.php

i hope it will help you…