[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:


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

)); ?>


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


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 )


Connecting to %s