View url and AccessRules


I would like to enable urls in function of the accessRules of a controller. With the current structure of the CAccessController I can’t do this without to load each controllers for each urls that I need to check.

For example, I am in the route site/index and in the view I want to display an url that point to the route hello/index only if the user respect the accessrules of this route.

How can I do this?

Right now, I am thinking about to rewrite my own access controller with the access Rules in an external file. Do you have any other idea?

How about the checkAccess method ? :rolleyes:

Yii not that bad, just read the documentations and wiki ;)

Start from here

I agree with dckurushin: checkAccess is the key. It will be weird for a successful PHP framework like Yii if it doesn’t have this very basic feature.

I used Rights with one of my projects and it performed pretty well. It uses database authorization manager so you don’t have to write anything to an external file. You might want to check it out.

But checkAccess is to check if the user fit to a role, task or operation. But in the accessRules of a controller, we dont check only for roles. And anyway, when I want to had an url to access to an action of my controller, I want to know if the user can access to this action. At the end, it’s my controller who is check the authorization with the accessRules, so why should I use checkAccess? And if one day, I want to change the accessRules of my controller, so I will have to update the code checking if I should display or not the url…

I think there is a structure issue in Yii about access control.