Commit 42cdd20e77aea4c42e24b1398d4aab261f1d35bc
1 parent
23cc5cba
-Added url helper
Showing
2 changed files
with
40 additions
and
1 deletions
Show diff stats
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace frontend\helpers; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | + class Url extends \artbox\core\helpers\Url | ||
| 7 | + { | ||
| 8 | + /** | ||
| 9 | + * @param bool $scheme | ||
| 10 | + * @param string $languagesClass | ||
| 11 | + * | ||
| 12 | + * @return string | ||
| 13 | + * @throws \yii\base\InvalidConfigException | ||
| 14 | + * @throws \yii\di\NotInstantiableException | ||
| 15 | + */ | ||
| 16 | + public static function home($scheme = false, $languagesClass = 'artbox\core\services\Languages') | ||
| 17 | + { | ||
| 18 | + /** | ||
| 19 | + * @var \artbox\core\services\Languages $languages | ||
| 20 | + * @var \artbox\core\seo\UrlManager $urlManager | ||
| 21 | + */ | ||
| 22 | + $languages = \Yii::$container->get($languagesClass); | ||
| 23 | + | ||
| 24 | + $url = '/' . $languages->getCurrent()->url; | ||
| 25 | + | ||
| 26 | + $urlManager = \Yii::$app->urlManager; | ||
| 27 | + | ||
| 28 | + if (( $languages->getCurrent()->id === $languages->getDefault( | ||
| 29 | + )->id ) && $urlManager->hideDefaultLanguagePrefix) { | ||
| 30 | + $url = '/'; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + if ($scheme !== false) { | ||
| 34 | + $url = $urlManager->getHostInfo() . $url; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + return $url; | ||
| 38 | + } | ||
| 39 | + } | ||
| 0 | \ No newline at end of file | 40 | \ No newline at end of file |
frontend/views/layouts/main.php
| @@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
| 23 | use yii\bootstrap\Nav; | 23 | use yii\bootstrap\Nav; |
| 24 | use yii\bootstrap\Html; | 24 | use yii\bootstrap\Html; |
| 25 | use yii\db\ActiveQuery; | 25 | use yii\db\ActiveQuery; |
| 26 | - use artbox\core\helpers\Url; | 26 | + use frontend\helpers\Url; |
| 27 | use yii\web\View; | 27 | use yii\web\View; |
| 28 | use yii\widgets\Breadcrumbs; | 28 | use yii\widgets\Breadcrumbs; |
| 29 | 29 |