Commit f3b6b9b186ada670465c6dec317ee477cf0ede1a
1 parent
3fa9a3b6
-Seo component in process
Showing
3 changed files
with
72 additions
and
4 deletions
Show diff stats
frontend/config/main.php
| 1 | <?php | 1 | <?php |
| 2 | -$params = array_merge( | 2 | + use artbox\core\components\LanguageRequest; |
| 3 | + use artbox\core\components\SeoUrlManager; | ||
| 4 | + | ||
| 5 | + $params = array_merge( | ||
| 3 | require(__DIR__ . '/../../common/config/params.php'), | 6 | require(__DIR__ . '/../../common/config/params.php'), |
| 4 | require(__DIR__ . '/../../common/config/params-local.php'), | 7 | require(__DIR__ . '/../../common/config/params-local.php'), |
| 5 | require(__DIR__ . '/params.php'), | 8 | require(__DIR__ . '/params.php'), |
| @@ -14,8 +17,9 @@ return [ | @@ -14,8 +17,9 @@ return [ | ||
| 14 | 'controllerNamespace' => 'frontend\controllers', | 17 | 'controllerNamespace' => 'frontend\controllers', |
| 15 | 'components' => [ | 18 | 'components' => [ |
| 16 | 'request' => [ | 19 | 'request' => [ |
| 20 | + 'class' => LanguageRequest::className(), | ||
| 17 | 'csrfParam' => '_csrf-frontend', | 21 | 'csrfParam' => '_csrf-frontend', |
| 18 | - 'baseUrl' => '', | 22 | + 'baseUrl' => '', |
| 19 | ], | 23 | ], |
| 20 | 'user' => [ | 24 | 'user' => [ |
| 21 | 'identityClass' => 'common\models\User', | 25 | 'identityClass' => 'common\models\User', |
| @@ -39,9 +43,10 @@ return [ | @@ -39,9 +43,10 @@ return [ | ||
| 39 | 'errorAction' => 'site/error', | 43 | 'errorAction' => 'site/error', |
| 40 | ], | 44 | ], |
| 41 | 'urlManager' => [ | 45 | 'urlManager' => [ |
| 46 | + 'class' => SeoUrlManager::className(), | ||
| 42 | 'enablePrettyUrl' => true, | 47 | 'enablePrettyUrl' => true, |
| 43 | - 'showScriptName' => false, | ||
| 44 | - 'rules' => [ | 48 | + 'showScriptName' => false, |
| 49 | + 'rules' => [ | ||
| 45 | ], | 50 | ], |
| 46 | ], | 51 | ], |
| 47 | ], | 52 | ], |
| 1 | +<?php | ||
| 2 | + namespace frontend\controllers; | ||
| 3 | + | ||
| 4 | + use artbox\core\models\Page; | ||
| 5 | + use yii\helpers\Json; | ||
| 6 | + use yii\helpers\Url; | ||
| 7 | + use yii\web\Controller; | ||
| 8 | + use yii\web\NotFoundHttpException; | ||
| 9 | + | ||
| 10 | + /** | ||
| 11 | + * Class PageController | ||
| 12 | + * | ||
| 13 | + * @package frontend\controllers | ||
| 14 | + */ | ||
| 15 | + class PageController extends Controller | ||
| 16 | + { | ||
| 17 | + public function actionView($id) | ||
| 18 | + { | ||
| 19 | + $model = $this->findModel($id); | ||
| 20 | + | ||
| 21 | + var_dump(Url::to(Json::decode($model->lang->alias->route))); | ||
| 22 | + | ||
| 23 | + return $this->render( | ||
| 24 | + 'view', | ||
| 25 | + [ | ||
| 26 | + 'model' => $model, | ||
| 27 | + ] | ||
| 28 | + ); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + protected function findModel($id) | ||
| 32 | + { | ||
| 33 | + $model = Page::findOne($id); | ||
| 34 | + | ||
| 35 | + if (!empty($model)) { | ||
| 36 | + return $model; | ||
| 37 | + } else { | ||
| 38 | + throw new NotFoundHttpException('Model not found'); | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + } | ||
| 0 | \ No newline at end of file | 42 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + use artbox\core\models\Page; | ||
| 3 | + use yii\helpers\Url; | ||
| 4 | + use yii\web\View; | ||
| 5 | + | ||
| 6 | + /** | ||
| 7 | + * @var View $this | ||
| 8 | + * @var Page $model | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +?> | ||
| 12 | + | ||
| 13 | +<h1> | ||
| 14 | + <?= $model->lang->title ?> | ||
| 15 | + | ||
| 16 | + <?= Url::to( | ||
| 17 | + [ | ||
| 18 | + 'page/view', | ||
| 19 | + 'id' => 10, | ||
| 20 | + ] | ||
| 21 | + ) ?> | ||
| 22 | +</h1> | ||
| 0 | \ No newline at end of file | 23 | \ No newline at end of file |