/**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Template::find();
     $query->andFilterWhere(['language' => Yii::$app->language]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['name' => SORT_ASC]], 'pagination' => ['pageSize' => 50]]);
     // Join the entity model as a relation
     $query->joinWith(['translations']);
     // enable sorting for the related column
     $dataProvider->sort->attributes['name'] = ['asc' => ['name' => SORT_ASC], 'desc' => ['name' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * Finds the News model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return News 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(Yii::t('app', 'The requested item does not exist'));
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTemplate()
 {
     return $this->hasOne(Template::className(), ['id' => 'email_template_id']);
 }