Hello,
In my CGridView I have a custom button that I want to hide (set visibility to false) if a certain row exists in a table.
Here is my code:
'visible'=> function($data) use ($slot) {
if ( Meeting::model()->exists( "student_id = :student_id AND time = :time", array(":student_id"=>$data['id'], ":time"=>$slot) ) )
return false;
else
return true;
}
This code seems like it should work, but it doesn’t! When the criteria are met (i.e. there is a row in the ‘meeting’ table with ‘student_id’ = $data[‘id’] and ‘time’ = $slot) the button still remains visible.
The problem appears to be with my use of $data[‘id’]. If I leave the code like this:
'visible'=> function($data) use ($slot) {
if ( Meeting::model()->exists( "time = :time", array(":time"=>$slot) ) )
return false;
else
return true;
}
… it works, but I need to check the ID for this to function correctly. What am I doing wrong here? No errors are generated.
Thanks.