need to call a method in widget 'zii.widgets.grid.CGridView'

need to call a method in widget ‘zii.widgets.grid.CGridView’

my display page code is like

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

'id'=>'patients-grid',


'dataProvider'=>$model->search(),


'filter'=>$model,


'columns'=>array(


	'patient_id',


	'patient_lname',


	//'patient_fname',


	//'patient_mname',


	//'patient_dob',


	//'patient_gender',


	


	/*'patient_ssn_1',


	'patient_ssn_2',


	'patient_ssn_3',


	'patient_medcare_no',


	'patient_medcaid_no',


	*/


	


	'patient_medrec_no',





	 [b]array


              (


              'name'=>'prim_insurance_id',


              'value'=>'getName()',


               ),[/b]





	'prim_insurance_id',


	/*'patient_address',


	'patient_zip',


	'patient_city',


	'patient_state',


	'patient_emergency_name',


	*/


	


	array(


		'class'=>'CButtonColumn',


	),





),

)

); ?>


and in model metho

public function getName()

{


return 1;


}

error Fatal error: Call to undefined function getName() in C:\wamp\www\yii\framework\base\CComponent.php(618) : eval()'d code on line 1

Hi!

As far as I know, magic getters work well here.

That is to say, if you have the function getName() as a method of your model, you should be able to treat ‘name’ as simply another attribute of the model, so $model->name should return the results of the getName() method. Not only this, but you can also add an entry to the attributes names array to give your method a friendly name, like ‘name’ => ‘Primary Insurance ID’.

These should both then be taken into account automatically when you add name as a normal attribute column:

‘patient_ssn_3’,

‘patient_medcare_no’,

‘patient_medcaid_no’,

‘name’,

This works for me in CGridview anyway - I have one model which has two separate attributes - a path and a file name; in the model I have added a function getFullPath(), as well as an entry to the attribute names - ‘fullPath’ => ‘Full Path’;

and in my CGridView columns array I just add the line ‘fullPath’, and it all works!

Problem is that you called just a global(?) function getName()…

If this function is in the model you need to call it like


$model->getName()

or in CGridView case


$data->getName()

But it is cleaner to use the magic getter method of the model in this case surely…?

It is…

I just pointed to the author of the post where he made the error… and as the post title is "call a method in…"… I wanted to show how any method can be called from CGridView…

Fair enough! ;)

But is it possible to create a filter on a magic method variable? For example, I have a table of events with displayed_start_date and displayed_end_date, and I have a method in my model called getIsVisible(). I’d like to have a column in CGridView called Visible?, which calls my magic isVisible getter variable.

I’ve tried many ways of accomplishing this — declaring public $isVisible in the model, making sure the variable is in the search rule, etc. — but I keep getting errors.

Am I barking up the wrong tree?