Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
252f49b9
Commit
252f49b9
authored
Mar 10, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc fixes.
parent
d2656356
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
45 deletions
+46
-45
BaseUrl.php
framework/helpers/BaseUrl.php
+46
-45
No files found.
framework/helpers/BaseUrl.php
View file @
252f49b9
...
@@ -7,8 +7,9 @@
...
@@ -7,8 +7,9 @@
namespace
yii\helpers
;
namespace
yii\helpers
;
use
yii\base\InvalidParamException
;
use
Yii
;
use
Yii
;
use
yii\base\InvalidParamException
;
use
yii\web\Controller
;
/**
/**
* BaseUrl provides concrete implementation for [[Url]].
* BaseUrl provides concrete implementation for [[Url]].
...
@@ -26,9 +27,9 @@ class BaseUrl
...
@@ -26,9 +27,9 @@ class BaseUrl
* @param array|string $route route as a string or route and parameters in form of
* @param array|string $route route as a string or route and parameters in form of
* `['route', 'param1' => 'value1', 'param2' => 'value2']`.
* `['route', 'param1' => 'value1', 'param2' => 'value2']`.
*
*
* If there is a controller running relative routes are recognized:
* If there is a controller running
,
relative routes are recognized:
*
*
* - If the route is an empty string, the current [[\yii\web\Controller::route]] will be used;
* - If the route is an empty string, the current [[\yii\web\Controller::route
|route
]] will be used;
* - If the route contains no slashes at all, it is considered to be an action ID
* - If the route contains no slashes at all, it is considered to be an action ID
* of the current controller and will be prepended with [[\yii\web\Controller::uniqueId]];
* of the current controller and will be prepended with [[\yii\web\Controller::uniqueId]];
* - If the route has no leading slash, it is considered to be a route relative
* - If the route has no leading slash, it is considered to be a route relative
...
@@ -36,26 +37,26 @@ class BaseUrl
...
@@ -36,26 +37,26 @@ class BaseUrl
*
*
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
*
*
* @param boolean|string $schem
a URI schema
to use:
* @param boolean|string $schem
e URI scheme
to use:
*
*
* - `false`: relative URL. Default behavior.
* - `false`: relative URL. Default behavior.
* - `true`: absolute URL with the current scheme.
* - `true`: absolute URL with the current scheme.
* - string: absolute URL with string value used as schem
a
.
* - string: absolute URL with string value used as schem
e
.
*
*
* @return string the
normalized URL
* @return string the
URL for the route
* @throws InvalidParamException if the parameter is invalid.
* @throws InvalidParamException if the parameter is invalid.
*/
*/
public
static
function
toRoute
(
$route
,
$schem
a
=
false
)
public
static
function
toRoute
(
$route
,
$schem
e
=
false
)
{
{
$route
=
(
array
)
$route
;
$route
=
(
array
)
$route
;
if
(
Yii
::
$app
->
controller
instanceof
\yii\web\
Controller
)
{
if
(
Yii
::
$app
->
controller
instanceof
Controller
)
{
$route
[
0
]
=
static
::
getNormalizedRoute
(
$route
[
0
]);
$route
[
0
]
=
static
::
getNormalizedRoute
(
$route
[
0
]);
}
}
if
(
$schem
a
)
{
if
(
$schem
e
)
{
if
(
$schem
a
===
true
)
{
if
(
$schem
e
===
true
)
{
$schem
a
=
null
;
$schem
e
=
null
;
}
}
$url
=
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$route
,
$schem
a
);
$url
=
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$route
,
$schem
e
);
}
else
{
}
else
{
$url
=
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
);
$url
=
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
);
}
}
...
@@ -63,12 +64,12 @@ class BaseUrl
...
@@ -63,12 +64,12 @@ class BaseUrl
}
}
/**
/**
* Normalizes route
making
it suitable for UrlManager. Absolute routes are staying as is
* Normalizes route
and makes
it suitable for UrlManager. Absolute routes are staying as is
* while relative routes are converted to absolute
rout
es.
* while relative routes are converted to absolute
on
es.
*
*
* A relative route is a route without a leading slash, such as "view", "post/view".
* A relative route is a route without a leading slash, such as "view", "post/view".
*
*
* - If the route is an empty string, the current [[\yii\web\Controller::route]] will be used;
* - If the route is an empty string, the current [[\yii\web\Controller::route
|route
]] will be used;
* - If the route contains no slashes at all, it is considered to be an action ID
* - If the route contains no slashes at all, it is considered to be an action ID
* of the current controller and will be prepended with [[\yii\web\Controller::uniqueId]];
* of the current controller and will be prepended with [[\yii\web\Controller::uniqueId]];
* - If the route has no leading slash, it is considered to be a route relative
* - If the route has no leading slash, it is considered to be a route relative
...
@@ -90,36 +91,36 @@ class BaseUrl
...
@@ -90,36 +91,36 @@ class BaseUrl
}
}
/**
/**
* Creates a
link
specified by the input parameter.
* Creates a
URL
specified by the input parameter.
*
*
* If the input parameter
* If the input parameter
is
*
*
* -
is
an array: the first array element is considered a route, while the rest of the name-value
* - an array: the first array element is considered a route, while the rest of the name-value
* pairs are treated as the parameters to be used for URL creation using [[toRoute]].
* pairs are treated as the parameters to be used for URL creation using [[toRoute
()
]].
* For example: `['post/index', 'page' => 2]`, `['index']`.
* For example: `['post/index', 'page' => 2]`, `['index']`.
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
* -
is
an empty string: the currently requested URL will be returned;
* - an empty string: the currently requested URL will be returned;
* -
is
a non-empty string: it will first be processed by [[Yii::getAlias()]]. If the result
* - a non-empty string: it will first be processed by [[Yii::getAlias()]]. If the result
* is an absolute URL, it will be returned either without any change or, if schem
a was specified, with schema
* is an absolute URL, it will be returned either without any change or, if schem
e was specified, with scheme
* replaced; Otherwise, the result will be prefixed with [[\yii\web\Request::baseUrl]] and returned.
* replaced; Otherwise, the result will be prefixed with [[\yii\web\Request::baseUrl]] and returned.
*
*
* @param array|string $url the parameter to be used to generate a valid URL
* @param array|string $url the parameter to be used to generate a valid URL
* @param boolean|string $schem
a URI schema
to use:
* @param boolean|string $schem
e URI scheme
to use:
*
*
* - `false`: relative URL. Default behavior.
* - `false`: relative URL. Default behavior.
* - `true`: absolute URL with the current scheme.
* - `true`: absolute URL with the current scheme.
* - string: absolute URL with string value used as schem
a
.
* - string: absolute URL with string value used as schem
e
.
*
*
* @return string the normalized URL
* @return string the normalized URL
* @throws InvalidParamException if the parameter is invalid.
* @throws InvalidParamException if the parameter is invalid.
*/
*/
public
static
function
to
(
$url
=
''
,
$schem
a
=
false
)
public
static
function
to
(
$url
=
''
,
$schem
e
=
false
)
{
{
if
(
is_array
(
$url
))
{
if
(
is_array
(
$url
))
{
return
static
::
toRoute
(
$url
,
$schem
a
);
return
static
::
toRoute
(
$url
,
$schem
e
);
}
elseif
(
$url
===
''
)
{
}
elseif
(
$url
===
''
)
{
if
(
$schem
a
)
{
if
(
$schem
e
)
{
$url
=
Yii
::
$app
->
getRequest
()
->
getAbsoluteUrl
();
$url
=
Yii
::
$app
->
getRequest
()
->
getAbsoluteUrl
();
}
else
{
}
else
{
$url
=
Yii
::
$app
->
getRequest
()
->
getUrl
();
$url
=
Yii
::
$app
->
getRequest
()
->
getUrl
();
...
@@ -130,25 +131,26 @@ class BaseUrl
...
@@ -130,25 +131,26 @@ class BaseUrl
if
(
$url
===
''
||
(
$url
[
0
]
!==
'/'
&&
$url
[
0
]
!==
'#'
&&
strncmp
(
$url
,
'./'
,
2
)))
{
if
(
$url
===
''
||
(
$url
[
0
]
!==
'/'
&&
$url
[
0
]
!==
'#'
&&
strncmp
(
$url
,
'./'
,
2
)))
{
$url
=
Yii
::
$app
->
getRequest
()
->
getBaseUrl
()
.
'/'
.
$url
;
$url
=
Yii
::
$app
->
getRequest
()
->
getBaseUrl
()
.
'/'
.
$url
;
}
}
if
(
$schem
a
)
{
if
(
$schem
e
)
{
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
$url
;
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
$url
;
}
}
}
}
}
}
if
(
$schem
a
&&
$schema
!==
true
)
{
if
(
$schem
e
&&
$scheme
!==
true
)
{
$pos
=
strpos
(
$url
,
'://'
);
$pos
=
strpos
(
$url
,
'://'
);
if
(
$pos
!==
false
)
{
if
(
$pos
!==
false
)
{
$url
=
$schem
a
.
substr
(
$url
,
$pos
);
$url
=
$schem
e
.
substr
(
$url
,
$pos
);
}
}
}
}
return
$url
;
return
$url
;
}
}
/**
/**
* Remembers
URL passed
* Remembers
the specified URL so that it can be later fetched back.
*
*
* @param string $url URL to remember. Default is current URL.
* @param string $url URL to remember. Default is the currently requested URL.
* @param string $name Name to use to remember URL. Defaults to `yii\web\User::returnUrlParam`.
* @param string $name Name to use to remember URL. Defaults to [[\yii\web\User::returnUrlParam]].
* @see previous()
*/
*/
public
static
function
remember
(
$url
=
''
,
$name
=
null
)
public
static
function
remember
(
$url
=
''
,
$name
=
null
)
{
{
...
@@ -164,10 +166,11 @@ class BaseUrl
...
@@ -164,10 +166,11 @@ class BaseUrl
}
}
/**
/**
* Returns
URL previously saved with remember method
* Returns
the URL previously [[remember()|remembered]].
*
*
* @param string $name Name used to remember URL. Defaults to `yii\web\User::returnUrlParam`.
* @param string $name Name used to remember URL. Defaults to [[\yii\web\User::returnUrlParam]].
* @return string URL
* @return string URL, or null if no such URL was remembered before.
* @see remember()
*/
*/
public
static
function
previous
(
$name
=
null
)
public
static
function
previous
(
$name
=
null
)
{
{
...
@@ -198,23 +201,23 @@ class BaseUrl
...
@@ -198,23 +201,23 @@ class BaseUrl
}
}
/**
/**
* Returns
home URL
* Returns
the home URL.
*
*
* @param boolean|string $schem
a URI schema
to use:
* @param boolean|string $schem
e URI scheme
to use:
*
*
* - `false`: relative URL. Default behavior.
* - `false`: relative URL. Default behavior.
* - `true`: absolute URL with the current scheme.
* - `true`: absolute URL with the current scheme.
* - string: absolute URL with string value used as schem
a
.
* - string: absolute URL with string value used as schem
e
.
*
*
* @return string home URL
* @return string home URL
*/
*/
public
static
function
home
(
$schem
a
=
false
)
public
static
function
home
(
$schem
e
=
false
)
{
{
if
(
$schem
a
)
{
if
(
$schem
e
)
{
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
Yii
::
$app
->
getHomeUrl
();
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
Yii
::
$app
->
getHomeUrl
();
if
(
$schem
a
!==
true
)
{
if
(
$schem
e
!==
true
)
{
$pos
=
strpos
(
$url
,
'://'
);
$pos
=
strpos
(
$url
,
'://'
);
$url
=
$schem
a
.
substr
(
$url
,
$pos
);
$url
=
$schem
e
.
substr
(
$url
,
$pos
);
}
}
}
else
{
}
else
{
$url
=
Yii
::
$app
->
getHomeUrl
();
$url
=
Yii
::
$app
->
getHomeUrl
();
...
@@ -222,4 +225,3 @@ class BaseUrl
...
@@ -222,4 +225,3 @@ class BaseUrl
return
$url
;
return
$url
;
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment