/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Template::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]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'layout_id', $this->layout_id]);
     return $dataProvider;
 }
 /**
  * @param FieldSetEvent $event
  */
 public function beforeFormRender($event)
 {
     $fieldSet = $event->fieldSet;
     $templateTab = new Tab('template', Module::t('template', 'Template'), [$fieldSet->getForm()->field($fieldSet->getModel(), 'template_id')->dropDownList(ArrayHelper::map(Template::find()->asArray()->all(), 'id', 'name'), ['prompt' => ''])->label(Module::t('template', 'Template'))]);
     $fieldSet->addItem($templateTab, 'tabs');
 }
 /**
  * Finds the Template model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Template the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Template::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Returns default template for layout.
  *
  * @param string $layout
  * @return Template
  */
 public function getDefaultTemplate($layout)
 {
     return Template::find()->where(['layout_id' => $layout, 'default' => 1])->one();
 }