コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Languages::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'is_default' => $this->is_default]);
     $query->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'locale', $this->locale])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
コード例 #2
0
ファイル: LocaleUrls.php プロジェクト: fonclub/yii2-languages
 /**
  * @inheritdoc
  */
 public function init()
 {
     $languages = Languages::find()->all();
     foreach ($languages as $lang) {
         $this->languages[$lang->url] = $lang->url;
         $labels[$lang->url] = $lang->name;
     }
     LanguageSwitcher::setLabels($labels);
     if (!Yii::$app->getRequest()->isConsoleRequest) {
         $this->_defaultLanguage = Yii::$app->language;
         $this->processRequest();
     }
     return parent::init();
 }
コード例 #3
0
 /**
  * Finds the Languages model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Languages the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Languages::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }