-
Notifications
You must be signed in to change notification settings - Fork 23
/
Module.php
117 lines (94 loc) · 3.49 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Project: yii2-blog for internal using
* Author: akiraz2
* Copyright (c) 2018.
*/
namespace akiraz2\blog;
use Yii;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'akiraz2\blog\controllers\frontend';
public $urlManager = 'urlManager';
public $imgFilePath = '@frontend/web/img/blog';
public $imgFileUrl = '/img/blog';
public $adminAccessControl = null;
public $blogPostPageCount = 10;
public $blogCommentPageCount = 20;
public $enableComments = false;
public $schemaOrg = [];
/** @var string Name of Component for editing posts */
public $redactorModule = 'redactorBlog';
/** @var linked user (for example, 'common\models\User::class' */
public $userModel;// = \common\models\User::class;
/** @var string Primary Key for user table, by default 'id' */
public $userPK = 'id';
/** @var string username uses in view (may be field `username` or `email` or `login`) */
public $userName = 'username';
public $blogTheme;
protected $_isBackend;
/**
*
*/
public function init()
{
parent::init();
if ($this->getIsBackend() === true) {
$this->setViewPath('@akiraz2/blog/views/backend');
} else {
$this->setViewPath('@akiraz2/blog/views/frontend');
//$this->setLayoutPath('@akiraz2/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('akiraz2/' . $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;
}
/**
* Need correct Full IMG URL for Backend
*
* @return string
*/
public function getImgFullPathUrl()
{
return \Yii::$app->get($this->urlManager)->getHostInfo() . $this->imgFileUrl;
}
}