diff --git a/common/config/main.php b/common/config/main.php index 25f88cc..ad48c82 100644 --- a/common/config/main.php +++ b/common/config/main.php @@ -1,4 +1,6 @@ dirname(dirname(__DIR__)) . '/vendor', 'components' => [ @@ -17,5 +19,8 @@ 'class' => 'yii2tech\filedb\Connection', 'path' => '@common/config', ], + 'seo' => [ + 'class' => SeoComponent::className(), + ], ], ]; diff --git a/frontend/controllers/PageController.php b/frontend/controllers/PageController.php index f33b2f7..eb00add 100644 --- a/frontend/controllers/PageController.php +++ b/frontend/controllers/PageController.php @@ -1,12 +1,14 @@ findModel($id); - + + /** + * @var SeoComponent $seo + */ + $seo = Yii::$app->get('seo'); + $seo->setModel($model->lang); + var_dump(Url::to(Json::decode($model->lang->alias->route))); - + return $this->render( 'view', [ @@ -27,12 +35,25 @@ ] ); } - + protected function findModel($id) { - $model = Page::findOne($id); - + /** + * @var Page $model + */ + $model = Page::find() + ->where( + [ + 'id' => $id, + ] + ) + ->with('lang') + ->one(); + if (!empty($model)) { + if ($model->lang->alias_id !== Yii::$app->seo->aliasId) { + throw new NotFoundHttpException('Wrong language'); + } return $model; } else { throw new NotFoundHttpException('Model not found'); diff --git a/frontend/views/page/view.php b/frontend/views/page/view.php index d90a921..bf4915e 100644 --- a/frontend/views/page/view.php +++ b/frontend/views/page/view.php @@ -1,4 +1,5 @@