T
T
The Dragger2015-05-11 08:37:10
Yii
The Dragger, 2015-05-11 08:37:10

How to get data through a garter?

<?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',
    ),
  ),
)); ?>

id comes to district_id, so I have to get the record from the garter.
Model.
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'),
    );
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
George, 2015-05-13
@gogametreveli

<?php $this->widget('bootstrap.widgets.TbGridView',array(
  'id'=>'ref-mahala-grid',
  'dataProvider'=>$model->with('region')->search(),
  'filter'=>$model,
  'columns'=>array(
    'id',
   // 'district_id',
   'region.нужное поле из класса RefRegion'
    'name_ru',
    'name_uz',
    'name_en',
    'address_ru',
    array(
      'class'=>'bootstrap.widgets.TbButtonColumn',
    ),
  ),
)); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question