0

Не понятно пытаюсь вывести фильтр (поиск) в gridview, не выводится.

public function actionIndex() {

    $model = new PackagesForm();
    $certificates = Certificate::find()->where(['certificates.user_id' => Yii::$app->user->identity->id,
        'package_id'=>null]);
    $packages = Packages::find()->where(['packages.user_id' => Yii::$app->user->identity->id]);
    $searchModel = new OfferSearch();
    $dataProvider = new ActiveDataProvider([
        'query' => $packages,
        'sort' => [
            'defaultOrder' => ['id' => SORT_DESC,'company' => SORT_DESC],
        ], 'pagination' => [
            'pageSize' => 10,
        ],
    ]);
    $dataCertificate = new ActiveDataProvider([
        'query' => $certificates,
        'sort' => [
            'defaultOrder' => ['id' => SORT_DESC],
        ], 'pagination' => [
            'pageSize' => 100,
        ],

`

 <?php
                echo GridView::widget([
                    'dataProvider' => $dataCertificate,
                    'filterModel' => $searchModel,
                    'columns' => [
                            [
                            'attribute' => 'certificate_code',
                            'label' => Yii::t('frontend', 'Code of certificate'),
                                  'filter'=>array("1"=>"Активно","2"=>"Не активно"),
                                ],

                            [
                            'attribute' => 'club_id',
                            'label' => Yii::t('frontend', 'Club'),
                            'value' => function ($data) {

                                $club = common\models\Club::findOne($data->club_id);
                                return $club->name;
                            },
                        ],
                            [
                            'attribute' => 'country_id',
                            'label' => Yii::t('frontend', 'Country'),
                            'value' => function ($data) {

                                $country = common\models\Country::findOne($data->country_id);
                                return $country->name;
                            }
                        ],
                            ['label' => Yii::t('frontend', 'Certificate costs'),
                            'attribute' => 'certificate_sum',],
                            [
                            'label' => Yii::t('frontend', 'Currency'),
                            'attribute' => 'certificate_currency',
                        ],
                            ['class' => 'yii\grid\CheckboxColumn',
                            'name' => 'certificates',
                            'checkboxOptions' => function ($model, $key, $index, $column) {
                                return ['value' => trim($model->certificate_code)];
                            }
                        ],
                    ],
                ]);
                ?>
1
  • OfferSearch покажите
    – Ninazu
    21 дек 2016 в 13:56

3 ответа 3

0

По-моему у вас разные типы

$dataCertificate представляет выборку по типу Certificate a модель фильтра $searchModel имеет тип OfferSearch

Попробуйте представить переменную $searchModel к типу Certificate или если есть у вас класс для поиска CertificateSearch

0

Спасибо нужно было правильно OfferSearch написать

0

В Search моделе посмотрите на rules, функция должна возвращать необходимые колонки с правилами валидации...

 /**
 * @inheritdoc
 */
public function rules()
{
    return [          
        [['name', 'slug'], 'string'],
    ];
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.