Validate flag in CGRidView to display certain value

Hi everyone.

I have a CGridView :

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









                      'value'=> 'CHtml::link(ProductCategory::model()->FindByPk($data->pc_id)->pc_name,array(\'productCategory/view\',\'id\'=>$data->pc_id))',





                      'value'=> 'CHtml::link(Coupon::model()->findByPk($data->item_id)->coupon_name,array(\'coupon/view\',\'id\'=>$data->item_id))',





                      'value'=> 'CHtml::link(Merchant::model()->FindByPk($data->merchant_id)->merchant_name,array(\'merchant/view\',\'id\'=>$data->merchant_id))',





                        'header' => 'Action',



)); ?>

So, from the above code, I retrieve the Coupon::model()->findByPk()… What I want to do is to validate the product category first (pc_id). If the pc_id == 1, then retrieve from Coupon, if 2, then retrieve from Merchandise. Can I do this using CGridView ? Thanks

sure you can , if the logic is too complex you can write a method to handle it :

in your model (the $data is an instance of your model class ) write an method to handle it :

       public function xxxx(&#036;productCate){

            //here you are  <img src='' class='bbc_emoticon' alt=':lol:' /> 

            //because this is in your model class you can directly access the pc_id------&#036;this-&gt;pc_id

                 if(&#036;this-&gt;pc_id == 1){

                     return Coupon::xxx...


                 if(&#036;this-&gt;pc_id == 2){

                     return Merchandise::xxx...



then : ‘value’=> 'CHtml::link($data->xxx(…)

you should understand what $data stand for :lol:

or you can write a static public function in any class then do like above , just consider how to pass the parameter :


wow, great, thanks a lot :)