Problem With CGridView

Hi All,

I am trying to use Zii widgets and I must say that using them saves a lot of effort .But I am stuck in a strange problem this time.

I have a custom function in my model that returns a string from my database on behalf of id.

I have successfully used it in CDetailView


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






                   'value' =&gt;&#036;model-&gt;ZoneName,




)); ?>

and it is working fine

It shows the Zone Name in place of Zone id(This is the functionality which I need)

I am trying to do the same with CgridView


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
















)); ?>

Here the label is coming up fine but value is not coming.It is coming as blank. I must be missing a very obvious point here.

Any help is highly appreciated…


You need to put it in your_model::search.

And in the rules function, make sure it’s set in the search scenario rule.

This should work better


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















Thanks a lot for paying attention to my problem.

If I use $data->ZoneName then its saying $data is undefined and as per my understanding it is giving correct error message as I havent defined anything as data.

This is the function I made in my model

public function getZoneName(){


           &#036;zoneName ='';

           if(trim(&#036;zoneId)&#33;=&quot;&quot; &amp;&amp; trim(&#036;zoneId)&#33;=NULL){

                   &#036;zoneNameObj  = Zone::model()-&gt;findbypk(&#036;zoneId,'',array('select'=&gt;'strZoneName'));        

                   &#036;zoneName =  &#036;zoneNameObj-&gt;strZoneName;


           return &#036;zoneName;


I have following search rules set in my model

public function search()


           // Warning: Please modify the following code to remove attributes that

           // should not be searched.

           &#036;criteria=new CDbCriteria;




           return new CActiveDataProvider(get_class(&#036;this), array(




and in my controller actionadmin I have

function actionAdmin(){

$model=new Division(‘search’);

$model->unsetAttributes(); // clear any default values






I hope I am a little more descriptive right now. Can u please guide me where am I going wrong


Thanks a Lot

It worked

I was missing single quotes ‘’ in my value field

Thnx all for paying attention


The $data variable exists locally when the CGridView rows are rendered (note the quotes around the ‘value’ value). I think you should include the zoneName property in a ‘select’ criteria when creating the dataprovider (not tested). See this example

(Please use [ code ] tags when providing code examples, for better readability. There’s a ‘<>’ button in the editor.)


Edit: Glad to hear you fixed it.