[Solved] Access To $Model Variable In Cgridview

EDIT: Ok, so using Meeting::model() works. But how can I find an appropriate expression that evaluates to true or false for the visible property?

Hello,

I have a view file with two CGridView widgets displaying data from two different tables. The first table shows meetings, and the second table shows guests (people who attend the meetings). The guests table has three buttons in each row; each button displays a time slot which users can press to create a meeting with the guest at that time.

When a user presses one of the buttons, a meeting will be created. To help prevent users from creating duplicate meetings, I would then like the button which was pressed to be disabled (or, at least hidden). To do this, the CGrideView for the guest table needs to have access to the meeting table, and a check must be done to see if there already exists an entry in the meeting table containing this specific guest name and time slot.

In my view code, I can add the following code for the ‘visible’ attribute in CButtonColumn:




'visible'=>'!$model->exists("name=:name AND time=:time",array(":name"=>$data->name,":time"=>"slot1"))',   // a PHP expression for determining whether the button is visible



But I get a notice telling me that $model is undefined, even though it should be available in the view file.

This is using the ‘visible’ attribute of CButtonColumn, however, if there is a way to simply disable the button instead of making it disappear completely, that would be much better.

Thanks.

echo ((Modelname::model()->findByAttributes(array(“name”=>$data->name,'time"=>“slot1”)))? (“true”) : (“false”));

I haven’t tried but you may try something like this.

Thanks ChiragChetan. I already tried the ternary operator / conditional expression operator and couldn’t get it to work. I didn’t use echo though, but I ended up using the following and it worked:




Meeting::model()->findByAttributes(array("name"=>$data->name,"time"=>"slot1")) == null



I just forgot to update this thread yesterday.