Как вытащить запись по id?

<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'ref-mahala-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'district_id',
'name_ru',
'name_uz',
'name_en',
'address_ru',
array(
  'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
)); ?>

в districk_id приходят ид , по этому ид я должен достать запись из подвязки.
Модель.
public function search()
{ // @todo Please modify the following code to remove attributes that should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id',$this->id);
$criteria->compare('district_id',$this->region['name_ru']);
$criteria->compare('name_ru',$this->name_ru,true);
$criteria->compare('name_en',$this->name_en,true);
$criteria->compare('address_ru',$this->address_ru,true);
$criteria->compare('address_en',$this->address_en,true);
$criteria->compare('sort',$this->sort);
$criteria->compare('active',$this->active);

return new CActiveDataProvider($this, array(
  'criteria'=>$criteria,
));
}
 public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
  'region' => array(self::BELONGS_TO, 'RefRegion', 'district_id'),
);
}
  • Вопрос задан
  • 197 просмотров
Решения вопроса 1
ARACOOOL
@ARACOOOL
PHP Developer
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'ref-mahala-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
array(
            'name' => 'district_id',
            'value' => '$data->region->name',
        ),
'name_ru',
'name_uz',
'name_en',
'address_ru',
array(
  'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
)); ?>


www.yiiframework.com/doc/api/1.1/CDataColumn
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы