コード例 #1
0
ファイル: DefaultController.php プロジェクト: Dominus77/blog
 /**
  * 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);
 }
コード例 #2
0
ファイル: PostSearch.php プロジェクト: bysobi/yiiblog
 /**
  * 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;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
ファイル: CategoryPosts.php プロジェクト: bysobi/blog
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPost()
 {
     return $this->hasOne(Post::className(), ['id' => 'post_id']);
 }
コード例 #5
0
ファイル: PostController.php プロジェクト: bysobi/yiiblog
 /**
  * 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.');
     }
 }
コード例 #6
0
ファイル: Category.php プロジェクト: Dominus77/blog
 /**
  * Возвращает количество опубликованых постов в категории
  * @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;
 }
コード例 #7
0
ファイル: PostComment.php プロジェクト: Dominus77/blog
 /**
  * @param $id
  * @return Post
  * @throws \yii\web\NotFoundHttpException
  */
 public function getModelMaterial($id)
 {
     $model = new Post();
     $post = $model->getPost($id);
     return $post;
 }
コード例 #8
0
ファイル: RecentPostsWidget.php プロジェクト: Dominus77/blog
 public function init()
 {
     parent::init();
     $model = new Post();
     $this->posts = $model->getRecentPosts($this->limit);
 }
コード例 #9
0
 /**
  * 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('Запрашиваемая страница не существует.');
     }
 }
コード例 #10
0
ファイル: Post.php プロジェクト: Dominus77/blog
 /**
  * Возвращает модель поста.
  * @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.');
     }
 }
コード例 #11
0
ファイル: Tags.php プロジェクト: Dominus77/blog
 /**
  * Возвращает посты по тегу
  * @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);
 }
コード例 #12
0
ファイル: DefaultController.php プロジェクト: bysobi/yiiblog
 public function actionIndex()
 {
     $models = Post::find()->all();
     return $this->render('index', ['models' => $models]);
 }