[Yii]CGridView:Display name from other model in columns


Riazul Karim Ivan

Here i have two model one is Main Category and another is Sub Category.

I have one to many relation between these two tables in database.

I have main category id in sub category table.

At first i generate code by gii.

Then if i want to show corresponding main category name in sub category CGridView:

<?php

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

‘columns’=>array(
‘id’,
        array(
                    ‘name’=>’main_id’,
                    ‘value’=>’CategoryGroupMain::model()->catMainGetName($data->main_id)’,
                ),            
‘name’,
array(
‘class’=>’CButtonColumn’,
),
),
)); ?>

——————————————————————————————————————————————————————————-

And in CategoryGroupMain model class i have to implement this function catMainGetName.

public function catMainGetName($pk)
    {
            $categoryGroupMainOb = CategoryGroupMain::model()->findByPk($pk);
            return $categoryGroupMainOb->name;
    }

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s