Commit cf77cbae6972024b85b4ba026457b67ed2f03333

Authored by Administrator
1 parent d29a2cfa

14.09.16

frontend/config/main.php
@@ -138,9 +138,9 @@ return [ @@ -138,9 +138,9 @@ return [
138 'brands' => 'catalog/brands', 138 'brands' => 'catalog/brands',
139 'brands/<brand:[\w\-]+>' => 'catalog/brand', 139 'brands/<brand:[\w\-]+>' => 'catalog/brand',
140 'blog' => 'articles/index', 140 'blog' => 'articles/index',
141 - 'blog/<translit:[\w\-]+>-<id:\d+>' => 'articles/show', 141 + 'blog/<translit:[\w\-\_]+>' => 'articles/show',
142 'event' => 'event/index', 142 'event' => 'event/index',
143 - 'event/<alias:[\w\-]+>-<id:\d+>' => 'event/show', 143 + 'event/<alias:[\w\-]+>' => 'event/show',
144 '<language:(ru|ua|en)>/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>', 144 '<language:(ru|ua|en)>/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
145 '<language:(ru|ua|en)>/<controller:\w+>/<action:\w+>' => '<controller>/<action>', 145 '<language:(ru|ua|en)>/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
146 '<language:(ru|ua|en)>/admin' => 'admin/default/index', 146 '<language:(ru|ua|en)>/admin' => 'admin/default/index',
frontend/controllers/ArticlesController.php
@@ -7,7 +7,7 @@ use yii\web\Controller; @@ -7,7 +7,7 @@ use yii\web\Controller;
7 use common\models\Articles; 7 use common\models\Articles;
8 use yii\web\HttpException; 8 use yii\web\HttpException;
9 use yii\data\Pagination; 9 use yii\data\Pagination;
10 - 10 +use yii\web\NotFoundHttpException;
11 class ArticlesController extends Controller 11 class ArticlesController extends Controller
12 { 12 {
13 13
@@ -30,13 +30,23 @@ class ArticlesController extends Controller @@ -30,13 +30,23 @@ class ArticlesController extends Controller
30 ]); 30 ]);
31 } 31 }
32 32
33 - public function actionShow(){  
34 - if(!$news = Articles::find()->where(['id'=>$_GET['id']])->one())  
35 - throw new HttpException(404, 'Данной странице не существует!'); 33 + public function actionShow($translit){
  34 + $news = $this->findModel($translit);
  35 +
36 36
37 - return $this->render('show', [  
38 - 'news'=>$news,  
39 - ]); 37 + return $this->render('show', [
  38 + 'news'=>$news,
  39 + ]);
  40 + }
  41 +
  42 +
  43 + protected function findModel($translit)
  44 + {
  45 + if (($model = Articles::findOne(["translit"=>$translit])) !== null) {
  46 + return $model;
  47 + } else {
  48 + throw new NotFoundHttpException('The requested page does not exist.');
  49 + }
40 } 50 }
41 51
42 } 52 }
43 \ No newline at end of file 53 \ No newline at end of file
frontend/views/articles/index.php
@@ -39,15 +39,13 @@ @@ -39,15 +39,13 @@
39 <div class="news_item"> 39 <div class="news_item">
40 <a href="<?= Url::to([ 40 <a href="<?= Url::to([
41 'articles/show', 41 'articles/show',
42 - 'translit' => $item->translit,  
43 - 'id' => $item->id, 42 + 'translit' => $item->translit
44 ]) ?>"> 43 ]) ?>">
45 <?= Html::img(\common\components\artboximage\ArtboxImageHelper::getImageSrc($item->imageUrl, 'list'), [ 'class' => 'float-left' ]) ?> 44 <?= Html::img(\common\components\artboximage\ArtboxImageHelper::getImageSrc($item->imageUrl, 'list'), [ 'class' => 'float-left' ]) ?>
46 </a> 45 </a>
47 <a href="<?= Url::to([ 46 <a href="<?= Url::to([
48 'articles/show', 47 'articles/show',
49 - 'translit' => $item->translit,  
50 - 'id' => $item->id, 48 + 'translit' => $item->translit
51 ]) ?>" class="name"><?= $item->title ?></a><br/> 49 ]) ?>" class="name"><?= $item->title ?></a><br/>
52 <div class="comment_display_block article_list_comment"> 50 <div class="comment_display_block article_list_comment">
53 <?php 51 <?php
@@ -63,7 +61,6 @@ @@ -63,7 +61,6 @@
63 echo Html::a(( $comment_count ? 'Отзывов: ' . count($item->comments) : "Оставить отзыв" ), [ 61 echo Html::a(( $comment_count ? 'Отзывов: ' . count($item->comments) : "Оставить отзыв" ), [
64 'articles/show', 62 'articles/show',
65 'translit' => $item->translit, 63 'translit' => $item->translit,
66 - 'id' => $item->id,  
67 '#' => 'artbox-comment', 64 '#' => 'artbox-comment',
68 ]); 65 ]);
69 ?> 66 ?>
frontend/views/event/_objects.php
@@ -9,11 +9,11 @@ FlipclockAsset::register($this); @@ -9,11 +9,11 @@ FlipclockAsset::register($this);
9 <div class="news_item"> 9 <div class="news_item">
10 <div> 10 <div>
11 <div> 11 <div>
12 - <a href="<?=Url::to(['event/show','alias'=>$model->alias,'id'=>$model->primaryKey])?>" class="name"><?=$model->name?></a> 12 + <a href="<?=Url::to(['event/show','alias'=>$model->alias])?>" class="name"><?=$model->name?></a>
13 </div> 13 </div>
14 14
15 <div style="position: relative"> 15 <div style="position: relative">
16 - <a href="<?=Url::to(['event/show','alias'=>$model->alias,'id'=>$model->primaryKey])?>"> 16 + <a href="<?=Url::to(['event/show','alias'=>$model->alias])?>">
17 <?= \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'event_left', ['align' => 'left'])?> 17 <?= \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'event_left', ['align' => 'left'])?>
18 </a> 18 </a>
19 19