Value Evaluated As Function

Hi all,

I am using v1.1.14 and I have the following problem:

I have two related tables, writer and company, where writer has an ID, FULLNAME, COMPANY_ID which is a foreign key to ID of company that additionally has NAME. In the view.php for writer, I have the following code to display the company when viewing a writer:




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

	'data'=>$model,

	'attributes'=>array(

    	array(

                	'label' => 'Company',

                	'value' => $model->company->name,

    	),

 	),

));



The problem is, if the company name happens to be a valid function, it is evaluated but not displayed as is. So, for example, if the company is ‘Time’, I get a timestamp instead of the string ‘Time’.

How can I display the string and not the result of the function? Using single or double quotes doesn’t help.

Thanks,

Rabb

Maybe try adding ‘type’=>‘text’ to the attribute definition.

nineinchnick, I’ve tried that, but still the same. And if I put ‘type’=>‘date’, the timestamp is formatted as a date, so it seems that first it is evaluated as function, then the format is applied.

It seems that the only solution is to edit CDetailView.php, which contains the following:


if(isset($attribute['value']))

  $value=is_callable($attribute['value']) ? call_user_func($attribute['value'],$this->data) : $attribute['value'];



Honestly, I do not think this is a good “feature”. It would be good to know the developers’ opinion.

Update - the following works, i.e. it displays the value as is and does not evaluate it as a function:




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


    	'data'=>$model,

    	'attributes'=>array(

        	array(

            	'label' => 'Company',

       		'name' => 'company.name',

        	),

    	),

));



I ran into this issue as well. It appears a fix has been implemented in the core: https://github.com/yiisoft/yii/issues/3010