Пример #1
0
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this->recordsPerPage]]);
     $query->andWhere(['app_id' => \Yii::$app->getModule('cms')->app_id]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->leftJoin(PostTranslate::tableName() . ' as tr ', '' . Post::tableName() . '.id = tr.post_id AND tr.language = \'' . Yii::$app->language . '\'');
     $query->andWhere(['like', 'tr.title', $this->title]);
     $this->addCondition($query, 'alias', true);
     $this->addCondition($query, 'views', true);
     $this->addCondition($query, 'status', true);
     $this->addCondition($query, 'author_id', true);
     return $dataProvider;
 }
Пример #2
0
 protected function findModel($id)
 {
     if (is_array($id)) {
         $model = Post::find()->where(['id' => $id])->all();
     } else {
         $model = Post::findOne($id);
     }
     if ($model !== null) {
         return $model;
     } else {
         throw new HttpException(404);
     }
 }