-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.php
163 lines (135 loc) · 2.92 KB
/
globals.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* This is the shortcut to DIRECTORY_SEPARATOR
*/
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
/**
* This is the shortcut to Yii::app()
*/
function app()
{
return Yii::app();
}
/**
* This is the shortcut to Yii::app()->request
*/
function request()
{
return Yii::app()->request;
}
/**
* This is the shortcut to Yii::app()->clientScript
*/
//function cs()
//{
// // You could also call the client script instance via Yii::app()->clientScript
// // But this is faster
// return Yii::app()->getClientScript();
//}
/**
* This is the shortcut to Yii::app()->user.
*/
function user()
{
return Yii::app()->getUser();
}
/**
* This is the shortcut to Yii::app()->createUrl()
*/
function url($route, $params = array(), $ampersand = '&')
{
return Yii::app()->createUrl($route, $params, $ampersand);
}
/**
* This is the shortcut to CHtml::encode
*/
function h($text)
{
return htmlspecialchars($text, ENT_QUOTES, Yii::app()->charset);
}
/**
* This is the shortcut to CHtml::link()
*/
function l($text, $url = '#', $htmlOptions = array())
{
return CHtml::link($text, $url, $htmlOptions);
}
/**
* This is the shortcut to CHtml::image()
*/
function img($src, $alt = '', $htmlOptions = array())
{
return CHtml::image($src, $alt, $htmlOptions);
}
/**
* This is the shortcut to Yii::t() with default category = 'app'
*/
function t($message, $category = 'app', $params = array(), $source = null, $language = null)
{
return Yii::t($category, $message, $params, $source, $language);
}
/**
* This is the shortcut to Yii::app()->request->baseUrl
* If the parameter is given, it will be returned and prefixed with the app baseUrl.
*/
function bu($url = null)
{
static $baseUrl;
if ($baseUrl === null)
$baseUrl = Yii::app()->getRequest()->getBaseUrl();
return $url === null ? $baseUrl : $baseUrl . '/' . ltrim($url, '/');
}
/**
* This is the shortcut to Yii::app()->theme->baseUrl
* If the parameter is given, it will be returned and prefixed with the app baseUrl.
*/
function theme($url = null)
{
static $baseUrl;
if ($baseUrl === null)
$baseUrl = Yii::app()->theme->baseUrl;
return $url === null ? $baseUrl : $baseUrl . '/' . ltrim($url, '/');
}
/**
* Returns the named application parameter.
* This is the shortcut to Yii::app()->params[$name].
*/
function param($name)
{
return Yii::app()->params[$name];
}
/**
* Returns the current language.
*/
function lang()
{
return Yii::app()->language;
}
/**
* Returns shared absolute path.
*/
function shared()
{
return Yii::app()->theme->basePath . "/views/shared/";
}
/**
* Calls Yii::log($var, 'error');
*/
function debug($var)
{
Yii::log($var, 'error');
}
/**
* Returns the token name for CSRF.
*/
function csrfTokenName()
{
return Yii::app()->request->csrfTokenName;
}
/**
* Returns the token for CSRF.
*/
function csrfToken()
{
return Yii::app()->request->getCsrfToken();
}