diff --git a/frontend/controllers/BlogController.php b/frontend/controllers/BlogController.php index 284763d..8cd6162 100644 --- a/frontend/controllers/BlogController.php +++ b/frontend/controllers/BlogController.php @@ -3,8 +3,11 @@ namespace frontend\controllers; use artbox\weblog\models\Article; + use artbox\weblog\models\Category; + use artbox\weblog\models\Tag; use yii\data\ActiveDataProvider; use yii\web\Controller; + use yii\web\NotFoundHttpException; /** * Class BlogController @@ -15,6 +18,13 @@ { public function actionIndex() { + $tags = Tag::find() + ->with( + [ + 'lang', + ] + ) + ->all(); $dataProvider = new ActiveDataProvider( [ 'query' => Article::find() @@ -22,6 +32,12 @@ [ 'created_at' => SORT_DESC, ] + ) + ->with( + [ + 'lang', + 'categories.lang', + ] ), 'pagination' => [ 'pageSize' => 3, @@ -32,8 +48,167 @@ return $this->render( 'index', [ + 'tags' => $tags, + 'dataProvider' => $dataProvider, + ] + ); + } + + public function actionArticle($id) + { + $model = $this->findModel($id); + + $tags = Tag::find() + ->with([ 'lang' ]) + ->all(); + + return $this->render( + 'view', + [ + 'tags' => $tags, + 'model' => $model, + ] + ); + } + + public function actionCategory($id) + { + $tags = Tag::find() + ->with( + [ + 'lang', + ] + ) + ->all(); + + /** + * @var Category $model + */ + $model = Category::find() + ->where( + [ + 'id' => $id, + ] + ) + ->with( + [ + 'articles', + ] + ) + ->one(); + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $model->getArticles() + ->with( + [ + 'lang', + 'categories.lang', + ] + ) + ->orderBy( + [ + 'created_at' => SORT_DESC, + ] + ), + 'pagination' => [ + 'pageSize' => 3, + ], + ] + ); + + return $this->render( + 'category', + [ + 'tags' => $tags, 'dataProvider' => $dataProvider, + 'model' => $model, ] ); } + + public function actionTag($id) + { + $tags = Tag::find() + ->with( + [ + 'lang', + ] + ) + ->all(); + + /** + * @var Category $model + */ + $model = Tag::find() + ->where( + [ + 'id' => $id, + ] + ) + ->with( + [ + 'articles', + ] + ) + ->one(); + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $model->getArticles() + ->with( + [ + 'lang', + 'categories.lang', + ] + ) + ->orderBy( + [ + 'created_at' => SORT_DESC, + ] + ), + 'pagination' => [ + 'pageSize' => 3, + ], + ] + ); + + return $this->render( + 'tag', + [ + 'tags' => $tags, + 'dataProvider' => $dataProvider, + 'model' => $model, + ] + ); + } + + /** + * @param $id + * + * @return Article + * @throws \yii\web\NotFoundHttpException + */ + protected function findModel($id) + { + /** + * @var Article | null $model + */ + $model = Article::find() + ->where([ 'id' => $id ]) + ->with( + [ + 'lang', + 'categories.lang', + 'tags.lang', + ] + ) + ->one(); + + if (empty($model)) { + throw new NotFoundHttpException(\Yii::t('app', 'Article not found')); + } else { + return $model; + } + } } \ No newline at end of file diff --git a/frontend/views/blog/_article.php b/frontend/views/blog/_article.php index 986f26d..7ee146f 100644 --- a/frontend/views/blog/_article.php +++ b/frontend/views/blog/_article.php @@ -1,6 +1,9 @@
-
-

Название статьи

+

lang->title; ?>

-

Автор: John Snow в Webdesign -

+ categories)) { ?> +

Без категории

+ categories as $category) { + $i++; + ?> +

lang->title, + [ + 'blog/category', + 'id' => $category->id, + ] + ); + if ($i === count($model->categories)) { + echo ' '; + } else { + echo ', '; + } + ?>

+

- 20 июня 2013 - 8 комментариев + formatter->asDate($model->created_at); ?> +

-

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. - Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

-

Продолжить чтение +

lang->body_preview; ?>

+

+ $model->id, + ], + [ + 'class' => 'btn btn-template-main', + ] + ) ?>

diff --git a/frontend/views/blog/category.php b/frontend/views/blog/category.php new file mode 100644 index 0000000..497467c --- /dev/null +++ b/frontend/views/blog/category.php @@ -0,0 +1,134 @@ +get('seo'); + + $this->params[ 'breadcrumbs' ][] = [ + 'label' => \Yii::t('app', 'Блог'), + 'url' => [ 'blog/index' ], + ]; + + $this->params[ 'breadcrumbs' ][] = $seo->title; + +?> + +
+
+
+ + + + + + + + + + + + + + $dataProvider, + 'itemView' => '_article', + 'options' => [ + 'class' => 'col-md-9', + 'id' => 'blog-listing-medium', + ], + 'layout' => '{items}{pager}', + ] + ); ?> + + + + + + +
+ + + + + + + + + + +
+ + + + +
+ +
+ +
+ \ No newline at end of file diff --git a/frontend/views/blog/index.php b/frontend/views/blog/index.php index 5ccc552..e050b79 100644 --- a/frontend/views/blog/index.php +++ b/frontend/views/blog/index.php @@ -1,13 +1,21 @@ get('seo'); + + $this->params[ 'breadcrumbs' ][] = $seo->title; ?> @@ -16,19 +24,15 @@
+ + + + + + + + -
- - - - - -
@@ -40,6 +44,7 @@ _________________________________________________________ --> 'class' => 'col-md-9', 'id' => 'blog-listing-medium', ], + 'layout' => '{items}{pager}', ] ); ?> @@ -94,16 +99,15 @@ _________________________________________________________ -->
diff --git a/frontend/views/blog/tag.php b/frontend/views/blog/tag.php new file mode 100644 index 0000000..af202a0 --- /dev/null +++ b/frontend/views/blog/tag.php @@ -0,0 +1,133 @@ +get('seo'); + + $this->params[ 'breadcrumbs' ][] = [ + 'label' => \Yii::t('app', 'Блог'), + 'url' => [ 'blog/index' ], + ]; + + $this->params[ 'breadcrumbs' ][] = $seo->title; + +?> + +
+
+
+ + + + + + + + + + + + + + $dataProvider, + 'itemView' => '_article', + 'options' => [ + 'class' => 'col-md-9', + 'id' => 'blog-listing-medium', + ], + 'layout' => '{items}{pager}', + ] + ); ?> + + + + + + +
+ + + + + + + + + + +
+ + + + +
+ +
+ +
+ \ No newline at end of file diff --git a/frontend/views/blog/view.php b/frontend/views/blog/view.php new file mode 100644 index 0000000..aa982b1 --- /dev/null +++ b/frontend/views/blog/view.php @@ -0,0 +1,242 @@ +params[ 'breadcrumbs' ][] = [ + 'label' => \Yii::t('app', 'Блог'), + 'url' => [ 'blog/index' ], + ]; + + $this->params[ 'breadcrumbs' ][] = $model->lang->title; + +?> + +
+
+ +
+ + + +
+ +

lang->title; ?>

+ + tags)) { ?> + + + +

formatter->asDate( + $model->created_at + ); ?>

+ +
+ + lang->body; ?> + +
+ + + +

2 comments

+ + +
+
+

+ +

+
+
+
Julie Alma
+

September 23, 2011 в 12:00

+

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. + Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

+

Ответить +

+
+
+ + + +
+ +
+

+ +

+
+ +
+
Louise Armero
+

23 сентября 2012 в 12:00

+

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. + Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

+

Ответить +

+
+ +
+ +
+ + + +
+ +

Leave comment

+ +
+
+ +
+
+ + +
+
+ +
+ +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+ +
+
+ + +
+ +
+ + */ + ?> +
+ + + + + + +
+ + + + + + + + + + +
+ + + + +
+ + +
+ +
+ + \ No newline at end of file -- libgit2 0.21.4