category
---------
id
category
status
category
---------
id
category_id
subcategory
status
I have created the model and CRUD using GII, now I want to display the category name on the subcategory crud admin page, could any help me on this ,
in models/subCategory.php
public function relations() { return array( 'category_id' => array(self::BELONGS_TO,'Category', 'id'), ); } public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( array('sub_category, status, created_date, category_id AS category_search, updated_date, updated_by', 'required'), array('category_id', 'numerical', 'integerOnly' => true), array('updated_by', 'numerical', 'integerOnly' => true), array('sub_category, status', 'length', 'max' => 255), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id,category_id, sub_category, status, category_search', 'safe', 'on' => 'search'), ); } public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria; $criteria->compare('id', $this->id); $criteria->together = true; $criteria->with = array( 'category_id' ); $criteria->compare('category_id.id', $this->category_search, true ); $criteria->compare('sub_category', $this->sub_category, true); $criteria->compare('status', $this->status, true); return new CActiveDataProvider($this, array( 'criteria' => $criteria, 'sort'=>array( 'attributes'=>array( 'category_search'=>array( 'asc'=>'category_id.category ASC', 'desc'=>'category_id.category DESC', ), '*', ), ), ));
in the view/subcategory/admin.php
$this->widget('zii.widgets.grid.CGridView', array( 'id'=>'sub-category-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array ( 'id', array( 'name'=>'category_search', 'header'=>'Category', 'sortable'=>false, 'value'=>$data->category_id->category ), 'sub_category', 'status', array( 'class'=>'CButtonColumn', ), ), ));
Can some one help me on this issue ?