Find us on facebook

Aug 8, 2014

Yii: working with multiple tables

public function rules()
{
return array(array('item_id', 'safe', 'on'=>'search'),);
}

public function relations()
{
return array(
'items'           => array(self::BELONGS_TO, 'Menu','item_id'),
)
}
public function attributeLabels()
{
return array('item_id'=>'Item Id',);
}

$criteria=new CDbCriteria;
$criteria->together = true;
$criteria->with = array('items');
$criteria->compare('id',$this->id);
$criteria->compare('type',$this->type);
$criteria->compare('items.name',$this->item_id);

view file

 array(
'name'=>'item_id',
'value'=>'$data->items->name',
),

No comments:

Post a Comment