| @@ 16-71 (lines=56) @@ | ||
| 13 | * |
|
| 14 | * @package app\controllers |
|
| 15 | */ |
|
| 16 | class ArticleController extends BaseController |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * @return array |
|
| 20 | */ |
|
| 21 | public function behaviors() |
|
| 22 | { |
|
| 23 | return ArrayHelper::merge(parent::behaviors(), [ |
|
| 24 | 'access' => [ |
|
| 25 | 'class' => AccessControl::class, |
|
| 26 | 'rules' => [ |
|
| 27 | [ |
|
| 28 | 'allow' => true, |
|
| 29 | 'actions' => ['view'], |
|
| 30 | 'roles' => ['?', '@'], |
|
| 31 | ], |
|
| 32 | ], |
|
| 33 | ], |
|
| 34 | 'verbs' => [ |
|
| 35 | 'class' => VerbFilter::class, |
|
| 36 | 'actions' => [ |
|
| 37 | 'view' => ['get'], |
|
| 38 | ], |
|
| 39 | ], |
|
| 40 | ]); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Displays article page. |
|
| 45 | * |
|
| 46 | * @return string |
|
| 47 | * |
|
| 48 | * @throws NotFoundHttpException |
|
| 49 | */ |
|
| 50 | public function actionView($alias) |
|
| 51 | { |
|
| 52 | $model = Article::find()->where([ |
|
| 53 | 'alias' => $alias |
|
| 54 | ])->andWhere([ |
|
| 55 | 'active' => 1 |
|
| 56 | ])->one(); |
|
| 57 | ||
| 58 | if (null === $model) { |
|
| 59 | throw new NotFoundHttpException('Article not fount with alias = '.$alias.'.'); |
|
| 60 | } |
|
| 61 | ||
| 62 | $this->setMetaParams($model); |
|
| 63 | ||
| 64 | $images = OwnerMediafile::getImageFiles(Article::tableName(), $model->id); |
|
| 65 | ||
| 66 | return $this->render('view', [ |
|
| 67 | 'model' => $model, |
|
| 68 | 'images' => $images |
|
| 69 | ]); |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||
| @@ 16-71 (lines=56) @@ | ||
| 13 | * |
|
| 14 | * @package app\controllers |
|
| 15 | */ |
|
| 16 | class ProductController extends BaseController |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * @return array |
|
| 20 | */ |
|
| 21 | public function behaviors() |
|
| 22 | { |
|
| 23 | return ArrayHelper::merge(parent::behaviors(), [ |
|
| 24 | 'access' => [ |
|
| 25 | 'class' => AccessControl::class, |
|
| 26 | 'rules' => [ |
|
| 27 | [ |
|
| 28 | 'allow' => true, |
|
| 29 | 'actions' => ['view'], |
|
| 30 | 'roles' => ['?', '@'], |
|
| 31 | ], |
|
| 32 | ], |
|
| 33 | ], |
|
| 34 | 'verbs' => [ |
|
| 35 | 'class' => VerbFilter::class, |
|
| 36 | 'actions' => [ |
|
| 37 | 'view' => ['get'], |
|
| 38 | ], |
|
| 39 | ], |
|
| 40 | ]); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Displays product page. |
|
| 45 | * |
|
| 46 | * @return string |
|
| 47 | * |
|
| 48 | * @throws NotFoundHttpException |
|
| 49 | */ |
|
| 50 | public function actionView($alias) |
|
| 51 | { |
|
| 52 | $model = Product::find()->where([ |
|
| 53 | 'alias' => $alias |
|
| 54 | ])->andWhere([ |
|
| 55 | 'active' => 1 |
|
| 56 | ])->one(); |
|
| 57 | ||
| 58 | if (null === $model) { |
|
| 59 | throw new NotFoundHttpException('Product not fount with alias = '.$alias.'.'); |
|
| 60 | } |
|
| 61 | ||
| 62 | $this->setMetaParams($model); |
|
| 63 | ||
| 64 | $images = OwnerMediafile::getImageFiles(Product::tableName(), $model->id); |
|
| 65 | ||
| 66 | return $this->render('view', [ |
|
| 67 | 'model' => $model, |
|
| 68 | 'images' => $images |
|
| 69 | ]); |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||