public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     if ($pathInfo == 'blog' || $pathInfo == 'blog/index') {
         $params = [];
         return ['blog/blogposts/index', $params];
     }
     if (preg_match('%^blog/category/(.*)%', $pathInfo, $matches)) {
         $category = $matches[1];
         $blogCategory = BlogTerms::find()->where('slug LIKE :slug', [':slug' => $category])->one();
         if ($blogCategory) {
             $params = ['id' => $blogCategory->id];
             return ['blog/blogposts/category', $params];
         } else {
             return false;
         }
     }
     if (preg_match('%^blog/(\\w+)/(\\w+)/(\\w+)/(.*)%', $pathInfo, $matches)) {
         // check $matches[1] and $matches[3] to see
         // if they match a manufacturer and a model in the database
         // If so, set $params['manufacturer'] and/or $params['model']
         // and return ['car/index', $params]
         $date = $matches[1] . '-' . $matches[2] . '-' . $matches[3] . '%';
         $blogPost = BlogPosts::find()->where('date LIKE :date AND slug = :slug', [':date' => $date, ':slug' => $matches[4]])->one();
         if ($blogPost) {
             $params['id'] = $blogPost->id;
             return ['blog/blogposts/view', $params];
         } else {
             return false;
             // this rule does not apply
         }
     }
     return false;
     // this rule does not apply
 }
 public function search($params)
 {
     $query = BlogPostsModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date_gmt' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'comments' => $this->comments, 'date' => $this->date, 'date_gmt' => $this->date_gmt, 'modified' => $this->modified, 'modified_gmt' => $this->modified_gmt]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'thumbnail', $this->thumbnail])->andFilterWhere(['like', 'excerpt', $this->excerpt])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'slug', $this->slug]);
     return $dataProvider;
 }
 public function run()
 {
     if (isset(\Yii::$app->params['recentBlogPostsWidget']) && is_int(\Yii::$app->params['recentBlogPostsWidget'])) {
         $limit = \Yii::$app->params['recentBlogPostsWidget'];
     } else {
         $limit = 4;
     }
     $posts = BlogPosts::find()->orderBy('date_gmt desc')->limit($limit)->all();
     if (empty($posts)) {
         echo '<p>No posts to display.</p>';
     } else {
         echo '<ul class="list-unstyled">' . $this->renderPosts($posts) . '</ul>';
     }
 }
 public function getPosts()
 {
     return $this->hasMany(BlogPosts::className(), ['id' => 'post_id'])->viaTable('{{%blog_term_relationships}}', ['term_id' => 'id'])->orderBy(['date_gmt' => SORT_DESC]);
 }
 /**
  * Finds the BlogPosts model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return BlogPosts the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BlogPosts::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPost()
 {
     return $this->hasOne(BlogPosts::className(), ['id' => 'post_id']);
 }