1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\controllers; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\db\ActiveRecord; |
7
|
|
|
use yii\web\Controller; |
8
|
|
|
use app\helpers\BaseHelper; |
9
|
|
|
use app\models\{Page, Category, Contact}; |
10
|
|
|
use app\traits\LanguageTrait; |
11
|
|
|
use Itstructure\AdminModule\models\Language; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class BaseController |
15
|
|
|
* |
16
|
|
|
* @package app\controllers |
17
|
|
|
*/ |
18
|
|
|
class BaseController extends Controller |
19
|
|
|
{ |
20
|
|
|
use LanguageTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
public $layout = '@app/views/layouts/base'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \yii\base\Action $action |
29
|
|
|
* |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
|
|
public function beforeAction($action) |
33
|
|
|
{ |
34
|
|
|
$this->view->params['pages'] = Page::getActiveMenu(); |
35
|
|
|
$this->view->params['categories'] = Category::getActiveMenu(); |
36
|
|
|
$this->view->params['contacts'] = Contact::getDefaultContacts(); |
37
|
|
|
$this->view->params['controllerId'] = Yii::$app->controller->id; |
38
|
|
|
|
39
|
|
|
return parent::beforeAction($action); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param ActiveRecord|null $model |
44
|
|
|
*/ |
45
|
|
|
protected function setMetaParams(ActiveRecord $model = null) |
46
|
|
|
{ |
47
|
|
|
if (null === $model) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->view->title = $model->{'title_'.$this->shortLanguage}; |
52
|
|
|
|
53
|
|
|
$this->view->registerMetaTag([ |
54
|
|
|
'name' => 'keywords', |
55
|
|
|
'content' => $model->{'metaKeys_'.$this->shortLanguage} |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
$this->view->registerMetaTag([ |
59
|
|
|
'name' => 'description', |
60
|
|
|
'content' => $model->{'metaDescription_'.$this->shortLanguage} |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
$this->view->registerLinkTag([ |
64
|
|
|
'rel' => 'canonical', |
65
|
|
|
'href' => rtrim(Yii::$app->request->absoluteUrl, '/') |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
$this->view->registerLinkTag([ |
69
|
|
|
'rel' => 'alternate', |
70
|
|
|
'hreflang' => 'x-default', |
71
|
|
|
'href' => Yii::$app->request->hostInfo |
72
|
|
|
]); |
73
|
|
|
|
74
|
|
|
foreach (Language::getShortLanguageList() as $shortName) { |
75
|
|
|
$this->view->registerLinkTag([ |
76
|
|
|
'rel' => 'alternate', |
77
|
|
|
'hreflang' => $shortName, |
78
|
|
|
'href' => rtrim(Yii::$app->request->hostInfo, '/') . |
79
|
|
|
BaseHelper::getSwitchLanguageLink($shortName, Yii::$app->request) |
|
|
|
|
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|