[Solved] Using Outside Variable In Cbuttoncolumn 'visible' Property

Hello,

I cannot use an external variable inside the ‘visible’ property of the CButtonColumn class.

Here is the minimum code required to understand my problem:




$this->widget('zii.widgets.grid.CGridView', array(

	'dataProvider'=>$dataProvider,

	'columns'=>array(

        'name',  // display the 'name' attribute

        array(

        	'class'=>'CButtonColumn',

        	'template'=>'{myButton}',

        	'buttons' => array(

        		'myButton' => array(

        			'label'=>$myValues[0], 

        			'visible'=>'Meeting::model()->exists( "value_id = :value_id AND time = :time",

        				array(":value_id"=>$data->id, ":time"=>$myValues[0]) ) == false',

        		),

        	)

        ),

    ),

));



This code produces the error "PHP notice: Undefined variable: myValues."

$myValues is an array which I have defined in my controller and passed into the view. I am able to use this variable in my ‘url’ property, but not my ‘visible’ property. I have tried all sorts of wizardry, including using anonymous functions (which is how I got ‘url’ to work with $data->id and my external variable).

How can I solve this problem?

Thanks.


'visible'=>'Meeting::model()->exists( "value_id = :value_id AND time = :time",

        array(":value_id"=>$data->id, ":time"=>' . $myValues[0] . ') ) == false',

When I use this, I get the following error:

Any other suggestions?

Is $myValues[0] a string? If so you need to put quotes around it.


'visible'=>'Meeting::model()->exists( "value_id = :value_id AND time = :time",

        array(":value_id"=>$data->id, ":time"=>"' . $myValues[0] . '") ) == false',

myValue is an array of strings. That works! Thank you Tsunami! :D