-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUrlManager.php
More file actions
42 lines (36 loc) · 1.13 KB
/
Copy pathUrlManager.php
File metadata and controls
42 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace abcms\multilanguage;
use Yii;
/**
* UrlManager extends \yii\web\UrlManager
* and adds lang param to each created url
* In configuration change urlManager component class to this className:
* 'urlManager' => [
'class'=> abcms\multilanguage\UrlManager::className(),
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'<lang:\w{2}>/<controller>/<id:\d+>/<urlTitle>/' => '<controller>/detail',
'<lang:\w{2}>/<controller>/<action>/' => '<controller>/<action>',
'<controller>/<id:\d+>/<urlTitle>/' => '<controller>/detail',
],
],
*/
class UrlManager extends \yii\web\UrlManager
{
/**
* @var boolean if true, add the lang param when creating a url
*/
public $languageInUrl = true;
/**
* @inheritdocs
*/
public function createUrl($params)
{
if($this->languageInUrl && !isset($params['lang'])) {
$params['lang'] = Yii::$app->language;
}
return parent::createUrl($params);
}
}