forked from funson86/yii2-blog
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathModule.php
72 lines (63 loc) · 2.55 KB
/
Module.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace funson86\blog;
use Yii;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'funson86\blog\controllers\frontend';
protected $_isBackend;
public function init()
{
parent::init();
if ($this->getIsBackend() === true) {
$this->setViewPath('@funson86/blog/views/backend');
} elseif (isset(Yii::$app->params['blogTheme'])) {
$this->setViewPath('@frontend/views/blog');
$this->setLayoutPath('@frontend/views/layouts');
} else {
$this->setViewPath('@funson86/blog/views/frontend');
$this->setLayoutPath('@funson86/blog/views/frontend/layouts');
}
}
/**
* Translates a message to the specified language.
*
* This is a shortcut method of [[\yii\i18n\I18N::translate()]].
*
* The translation will be conducted according to the message category and the target language will be used.
*
* You can add parameters to a translation message that will be substituted with the corresponding value after
* translation. The format for this is to use curly brackets around the parameter name as you can see in the following example:
*
* ```php
* $username = 'Alexander';
* echo \Yii::t('app', 'Hello, {username}!', ['username' => $username]);
* ```
*
* Further formatting of message parameters is supported using the [PHP intl extensions](http://www.php.net/manual/en/intro.intl.php)
* message formatter. See [[\yii\i18n\I18N::translate()]] for more details.
*
* @param string $category the message category.
* @param string $message the message to be translated.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en-US`, `en`). If this is null, the current
* [[\yii\base\Application::language|application language]] will be used.
*
* @return string the translated message.
*/
public static function t($category, $message, $params = [], $language = null)
{
return Yii::t('funson86/' . $category, $message, $params, $language);
}
/**
* Check if module is used for backend application.
*
* @return boolean true if it's used for backend application
*/
public function getIsBackend()
{
if ($this->_isBackend === null) {
$this->_isBackend = strpos($this->controllerNamespace, 'backend') === false ? false : true;
}
return $this->_isBackend;
}
}