Я буду приводить функции на yii 1.x, было бы интересно во что это превратилось в Yii 2.x
Вот старая функция search:
//Модель
Код: Выделить всё
**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('attributeType', 'attributesRu', 'attributesImages');
$criteria->compare('attributesRu.short_name', $this->shortName, true);
$criteria->compare('attributesRu.name', $this->longName, true);
$criteria->compare('attributesImages.src', $this->image);
$criteria->compare('t.id',$this->id);
$criteria->compare('t.type',$this->type);
$criteria->compare('t.disabled',$this->disabled);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'attributes'=>array(
'shortName'=>array(
'asc'=>'attributesRu.short_name',
'desc'=>'attributesRu.short_name DESC',
),
'longName'=>array(
'asc'=>'attributesRu.name',
'desc'=>'attributesRu.name DESC',
),
'*',
),
),
'pagination' => array(
'pageSize' => 15,
),
));
}
//Контроллер
Код: Выделить всё
public function actionIndex()
{
$model=new Attributes('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Attributes']))
$model->attributes=$_GET['Attributes'];
$types=AttributesTypes::model()->findAll();
if (isset($_GET['ajax'])) {
$this->renderPartial('_grid',array(
'model'=>$model,
'types'=>$types,
));
}
else {
$this->render('index',array(
'model'=>$model,
'types'=>$types,
));
}
}
//Вьюха
Код: Выделить всё
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'attributes-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'itemsCssClass'=>'table table-striped table-bordered',
'ajaxUpdate'=>true,
'htmlOptions'=>array('style'=>'margin:0px'),
'template'=>'{summary}{items}{pager}',
'columns'=>array(
array(
'type'=>'raw',
'name'=>'id',
'headerHtmlOptions'=>array('style'=>'width:40px;'),
'filterHtmlOptions'=>array('style'=>'height:0px; padding:5px'),
'filter'=>CHtml::textField('Attributes[id]', $model->id, array('style'=>'width:40px;margin:0px;')),
),
array(
'type'=>'html',
'name'=>'image',
'headerHtmlOptions'=>array('style'=>'width:40px;'),
'filterHtmlOptions'=>array('style'=>'height:0px; padding:5px'),
'htmlOptions'=>array('style'=>'padding:0px; margin:0px; text-align:center'),
'filter'=>false,
'value'=>'(!empty($data->attributesImages["src"]))?CHtml::image(Yii::app()->request->hostInfo.Yii::app()->baseUrl."/'.$this->thumbDir.'_".$data->attributesImages["src"],"",array("style"=>"width:31px;height:31px;line-height:normal")):""'
),
array(
'type'=>'raw',
'name'=>'type',
'headerHtmlOptions'=>array('style'=>'width:80px;'),
'filterHtmlOptions'=>array('style'=>'height:0px; padding:5px'),
'filter'=>CHtml::dropDownList('Attributes[type]', $model->type, CHtml::listData($types, 'id', 'name'), array('empty'=>'', 'style'=>'margin:0px;')),
'value'=>'$data->attributeType["name"]',
),
array(
'type'=>'raw',
'name'=>'disabled',
'headerHtmlOptions'=>array('style'=>'width:80px;'),
'filterHtmlOptions'=>array('style'=>'height:0px; padding:5px'),
'filter'=>CHtml::dropDownList('Attributes[disabled]', $model->disabled, array('empty'=>'', 1=>'Выкл.', 0=>'Вкл.'), array('style'=>'width:80px; margin:0px;')),
),
array(
'type'=>'raw',
'name'=>'shortName',
'headerHtmlOptions'=>array('style'=>'width:120px;'),
'filterHtmlOptions'=>array('style'=>'height:0px; padding:5px'),
'filter'=>CHtml::textField('Attributes[shortName]', $model->shortName, array('style'=>'width:120px;margin:0px;')),
'value'=>'$data->attributesRu["short_name"]',
),
array(
'type'=>'raw',
'name'=>'longName',
'filterHtmlOptions'=>array('style'=>'height:0px; padding:5px'),
'filter'=>CHtml::textField('Attributes[longName]', $model->longName, array('style'=>'width:250px;margin:0px;')),
'value'=>'$data->attributesRu["name"]',
),
array(
'class'=>'CButtonColumn',
),
),
));
- Вывод в колонку значений типа (disabled) ? Да : Нет
- Фильтрация по моделям со связями, именно по полям заJOINненой таблицы.
- Картинки в ячейках
--
ps:
Дайте, пожалуйста, ссылки на рецепты, если таковы существуют.