/** * Indexing Zend Lucene Search * @throws \yii\base\InvalidConfigException */ public function actionSearchIndexing() { /** @var \himiklab\yii2\search\Search $search */ if (Post::zendLuceneIndexing()) { Yii::$app->session->setFlash('success', Module::t('module', 'FLASH_INDEXING_SEARCH_SUCCESS')); } else { Yii::$app->session->setFlash('error', Module::t('module', 'FLASH_INDEXING_SEARCH_ERROR')); } return $this->redirect(['default/index'], 301); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Post::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, 'category_id' => $this->category_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Post::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, 'user_id' => $this->user_id, 'category_id' => $this->category_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getPost() { return $this->hasOne(Post::className(), ['id' => 'post_id']); }
/** * Finds the Post model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Post the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Post::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Возвращает количество опубликованых постов в категории * @param $id * @return integer */ public function getCountPosts($id) { $count = Post::find()->select(['COUNT(*) AS cnt'])->where(['category_id' => $id, 'publish_status' => Post::STATUS_PUBLISH])->count(); return $count; }
/** * @param $id * @return Post * @throws \yii\web\NotFoundHttpException */ public function getModelMaterial($id) { $model = new Post(); $post = $model->getPost($id); return $post; }
public function init() { parent::init(); $model = new Post(); $this->posts = $model->getRecentPosts($this->limit); }
/** * Finds the Post model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Post the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Post::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('Запрашиваемая страница не существует.'); } }
/** * Возвращает модель поста. * @param int $id * @throws NotFoundHttpException в случае, когда пост не найден или не опубликован * @return Post */ public function getPost($id) { if (($model = Post::findOne($id)) !== null && $model->isPublished() || $model->isArchive()) { return $model; } else { throw new NotFoundHttpException('The requested post does not exist.'); } }
/** * Возвращает посты по тегу * @return \yii\db\ActiveQuery */ public function getPostsTag($offset = false, $limit = false) { return $this->hasMany(Post::className(), ['id' => 'post_id'])->viaTable('{{%blog_tag_post}}', ['tag_id' => 'id'])->where(['publish_status' => [Post::STATUS_PUBLISH, Post::STATUS_ARCHIVE]])->orderBy(['id' => SORT_DESC])->offset($offset)->limit($limit); }
public function actionIndex() { $models = Post::find()->all(); return $this->render('index', ['models' => $models]); }