Does anybody know how this could be done. I have been pulling my hair out trying to get this to work whilst also being efficient…
My final aim is to hide links based on whether a user has permission to view page it points to. Extending CHTML requires me to convert the url string to a controller and action in order to check the permission.
Ideally you should build a URL using Yii::app()->createUrl,
maybe you can have that URL creation inside your Companies module.
that could be a good place to insert your logic, checking if the user have rights or stuff like that.
For instance, you could have something like this:
//in the Companies module
public function getUrlUpdate()
if (/*logic to check that the user is not allowed to follow this link */) return false;
return Yii::app()->createUrl('companies/update', array(
and then you can check if the url isn’t false before giving it to CHtml::link
Inside CHTML there is a link method. We call this to write our links. I want to extend this so before the link is returned the CONTROLLER/ACTION is checked to see if they have permission to access that page. If they dont, return false and the link will not be displayed on the page.
Problem is, once I am inside CHTML, the link that is passed is in the format abc.com/Controller/Action. I need to parse that into
array(controller, action) so I can check the permission use my permission checking function. I could indeed go through and add if statements to the links, but I was hoping to do the change in a central place so it gets applied to the whole site…(as its quite large)
The other way to handle this is to "explode" the url and assign the values to an array. Count the number of elements in the array and just take the last 2. (assuming .../controller/action is a consistent format of your URL) The first method (prior post) should work, however.