I’m wondering if there exists a method which accepts a controller/action and returns whether or not the current user must login to do that. I know it’s possible to do it the hard way by iterating through the access rules, but I’m wondering if there is already a method that will do it for me. I’ve search for a while now with no luck. I also don’t want to create custom roles and use checkAccess() for something as simple as this.
Does anyone know of such a method or can anyone recommend a way to accomplish what I’m after without manually searching through the access rules before I display each and every link?
The problem is that the accessRules() method doesn’t take a controller or action as the parameter, it takes an operation, and an operation must be correlated to a user role. My site isn’t complex enough to warrant user roles, logged-in and guest are all I need.
Also, the problem with the in_array() function is that if I’m currently on a page using the GroupController and I want to see if the ‘view’ action is allow to a guest in the UserController, I don’t seem to be able to instantiate a new UserController.
In other words:
$u = new UserController;
$rules = $u->accessRules();
and then in_array($rules) ...
This won’t work because apparently I don’t seem to be able to load a new controller without creating a new CWebApplication.
Any thoughts as to how this could be possible without creating a new application?
I understood from your initial description that the check would only be valid when you are within the same controller. But you may not be possible to check for different controllers unless the controller is loaded and you are performing the check for the loaded one. However, if you have are currently working in the environment of GroupController you can access the accessRules() through $this->. For example in one of your group view files print_r($this->accessRules());