I have a CGridView with records that only the original uploader or the admin can update/delete, otherwise no update/delete buttons should be displayed in the column (even though the empty column is there). I tried doing this in the visible property of the column, but realized that it is impossible for a column to be visible and invisible at the same time, so I suppose I should create the delete and update buttons, and then set the visible properties on them to be evaluated based on $data. I have a function on Yii::app()->user called adminOrOwner that takes an instance of a model and returns true if the user is an admin or is the original uploader, false if neither. This is my widget code so far:
I have found that the visible property is not evaluated at runtime like the value property. So, is there another way I can get access to the model of the current row?
I have thought some more on this, and figured that the best way to go about this (which is what I want exactly) is to have the conditional statement to alter the template property, rather than the visible property. However, the template property does not get evaluated, and I need an expression which is evaluated for every row that is created (I.E. something like the value property of a CDataColumn, which is evaluated every time a row is created, based on $data). Any ideas?
I finally got it to work! Reading a how-to about the CButtonColumn on the wiki and seeing the ‘visible’ property in the ‘buttons’ array mentioned there, an idea struck me. What if I wouldn’t care about the column itself or don’t mind the template, but hide the buttons using their ‘visible’ property that indeed gets evaluated for the each row, rather than just once! Well, that proved to be true. I’m pasting the solution here in case someone needs it:
Did you find solution how to do this ? I’m also trying to figure it out… Alternative solution would work also… put chtml::link inside cmenu widget so I could use ‘visible’ parameter, but I dont know how to do that either