CDetailView value expression

In CGridView, I am able to apply an expression to the value of a column like this:


  array(  'name'=>'f_user_admin',




Which allows me to display Yes or No, according to the database value of 1 or 0. Now it seems that the same functionality is not available in CDetailView. I have tried the code below, and the value comes out as, literally, ($data->f_user_admin===0)?"No":"Yes".

  array(  'name'=>'f_user_admin',




Does anyone have a suggestion as to how I can accomplish applying an expression within CDetailView? One would think the the same functionality that works in CGridView would work here.

Nothing? So what are my options here?

Maybe it is too obvious, but why are you using quotes when passing the value parameter?



should literally return "$name", while


should return "Haensel"

In hindsight, you’re right, it is obvious! The fact that the example I had found for the CGridView contained the quotes, and worked, is what threw me off.

Thanks for responding, despite my silly oversight. It has saved me needless headaches.

Actually, this does not work. I thought it did at first, but I just realized it’s not printing the correct value.

Please [post=‘92584’]see this post[/post] for more information. Any help in figuring this one out would be greatly appreciated.

So is there no way of applying an expression to a CDetailView value???

I just found an interesting, related thread: CDetailView with Function

The bottom line: it should work without single quotes on CDetailView and with single quotes on CGridView. You can try a function in place of the ternary (see link for example).

I know this post is quite old now, but I thought I’d just add that you can use ‘type’ => ‘boolean’ to get a ‘Yes|No’ value:

  array(  'name'=>'f_user_admin',



Or if it is not just boolean you simply do not need any expression since $model is available in your template:

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



        // ...








Is there a reason for using the identical operator (===) in your expression rather than just using the equal operator (==)? If you don’t have to verify the type of the value, then it’s not necessary. I set up a test with code similar to yours and once I switched the expression to remove the quotes and use the equal operator it worked with no issues:

array(  'name'=>'f_user_admin',


              'value'=>(($data->f_user_admin==0)? 'No' : 'Yes' )),


you can use

'value'=>'$data->action==null ? '' : $data->action->name',