'filterModel' => $searchModel

всем привет

что-то не возьму в толк = как сделать этот самый $searchModel

нужен хелп!

Сгенерируйте CRUD в gii, станет все понятно.

А вообще это класс который наследует модель, и реализует функцию search() которая в зависимости от параметров отдает dataProvider. Очень удобно, так как там можно сделать свои правила и сценарии.

Вот пример:




/** 

     * Lists all AffiliateTrafficSources models. 

     * @return mixed 

     */ 

    public function actionIndex() 

    { 

        $searchModel = new AffiliateTrafficSourcesSearch(); 

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 


        return $this->render('index', [ 

            'searchModel' => $searchModel, 

            'dataProvider' => $dataProvider, 

        ]); 

    } 






<?php


namespace app\modules\v1\models; 


use Yii; 

use yii\base\Model; 

use yii\data\ActiveDataProvider; 

use app\modules\v1\models\AffiliateTrafficSources; 


/** 

 * AffiliateTrafficSourcesSearch represents the model behind the search form about `app\modules\v1\models\AffiliateTrafficSources`.

 */ 

class AffiliateTrafficSourcesSearch extends AffiliateTrafficSources 

{ 

    /** 

     * @inheritdoc 

     */ 

    public function rules() 

    { 

        return [ 

            [['id', 'type', 'affiliate_id'], 'integer'],

            [['title', 'description'], 'safe'], 

        ]; 

    } 


    /** 

     * @inheritdoc 

     */ 

    public function scenarios() 

    { 

        // bypass scenarios() implementation in the parent class 

        return Model::scenarios(); 

    } 


    /** 

     * Creates data provider instance with search query applied 

     * 

     * @param array $params 

     * 

     * @return ActiveDataProvider 

     */ 

    public function search($params) 

    { 

        $query = AffiliateTrafficSources::find(); 


        $dataProvider = new ActiveDataProvider([ 

            'query' => $query, 

        ]); 


        $this->load($params); 


        if (!$this->validate()) { 

            // uncomment the following line if you do not want to return any records when validation fails

            // $query->where('0=1'); 

            return $dataProvider; 

        } 


        $query->andFilterWhere([

            'id' => $this->id,

            'type' => $this->type,

            'affiliate_id' => $this->affiliate_id,

        ]);


        $query->andFilterWhere(['like', 'title', $this->title])

            ->andFilterWhere(['like', 'description', $this->description]);


        return $dataProvider; 

    } 

} 



спасибо

я сам уже разобрался

пс: хотя gii, гад, не хочет запускаться