Hi guys.
First: i have googled this, and found endless ammount of forum-threads and tutorials, but i still cant seem to make it work.
I have a model called Wine. That has its country and region represented by a id.
I want the gridview to generate the region and country names, and allso the filterboxes to respond if you write the country or region name.
In my model:
public function relations()
{
return array(
'GetRegion' => array(self::BELONGS_TO, 'Region', 'region', 'alias' => 'r'),
'GetCountry' => array(self::BELONGS_TO, 'Country', 'country', 'alias' => 'c'),
);
}
My Controller:
public function actionIndex()
{
$model=new Wine('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Wine']))
$model->attributes=$_GET['Wine'];
$this->render('index', array(
'model'=>$model,
));
}
And my view:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'wine-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'name',
'region',
'country',
'year',
),
)); ?>
Ive tried with r.name/c.name and with $data->GetRegion->name, but errormessage on both.
Anyone have any inputs? Ive been stuck for hours
Thanks in advance!