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
8df9dddd
Commit
8df9dddd
authored
Mar 09, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Url::createAbsolute, adjusted signiatures
parent
2cd5f982
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
12 deletions
+36
-12
BaseUrl.php
framework/helpers/BaseUrl.php
+36
-12
No files found.
framework/helpers/BaseUrl.php
View file @
8df9dddd
...
@@ -34,35 +34,59 @@ class BaseUrl
...
@@ -34,35 +34,59 @@ class BaseUrl
* 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.
*
*
* @param array|string $url the parameter to be used to generate a valid URL
* @param array|string $params the parameter to be used to generate a valid URL
* @param boolean $absolute if absolute URL should be created
* @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
create
(
$
url
)
public
static
function
create
(
$
params
,
$absolute
=
false
)
{
{
if
(
is_array
(
$
url
))
{
if
(
is_array
(
$
params
))
{
if
(
isset
(
$
url
[
0
]))
{
if
(
isset
(
$
params
[
0
]))
{
if
(
Yii
::
$app
->
controller
instanceof
\yii\web\Controller
)
{
if
(
Yii
::
$app
->
controller
instanceof
\yii\web\Controller
)
{
return
Yii
::
$app
->
controller
->
createUrl
(
$url
);
return
$absolute
?
Yii
::
$app
->
controller
->
createAbsoluteUrl
(
$params
)
:
Yii
::
$app
->
controller
->
createUrl
(
$params
);
}
else
{
}
else
{
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$url
);
return
$absolute
?
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$params
)
:
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$params
);
}
}
}
else
{
}
else
{
throw
new
InvalidParamException
(
'The array specifying a URL must contain at least one element.'
);
throw
new
InvalidParamException
(
'The array specifying a URL must contain at least one element.'
);
}
}
}
elseif
(
$
url
===
''
)
{
}
elseif
(
$
params
===
''
)
{
return
Yii
::
$app
->
getRequest
()
->
getUrl
();
return
$absolute
?
Yii
::
$app
->
getRequest
()
->
getAbsoluteUrl
()
:
Yii
::
$app
->
getRequest
()
->
getUrl
();
}
else
{
}
else
{
$
url
=
Yii
::
getAlias
(
$url
);
$
params
=
Yii
::
getAlias
(
$params
);
if
(
$
url
!==
''
&&
(
$url
[
0
]
===
'/'
||
$url
[
0
]
===
'#'
||
strpos
(
$url
,
'://'
)
||
!
strncmp
(
$url
,
'./'
,
2
)))
{
if
(
$
params
!==
''
&&
(
$params
[
0
]
===
'/'
||
$params
[
0
]
===
'#'
||
strpos
(
$params
,
'://'
)
||
!
strncmp
(
$params
,
'./'
,
2
)))
{
return
$
url
;
return
$
params
;
}
else
{
}
else
{
return
static
::
base
(
$
url
);
return
static
::
base
(
$
params
);
}
}
}
}
}
}
/**
/**
* Normalizes the input parameter to be a valid absolute URL.
*
* If the input parameter
*
* - is 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
* is an absolute URL, it will be returned without any change further; Otherwise, the result
* will be prefixed with [[\yii\web\Request::baseUrl]] and returned.
* - is 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 [[\yii\web\Controller::createUrl()]].
* For example: `['post/index', 'page' => 2]`, `['index']`.
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
*
* @param array|string $params the parameter to be used to generate a valid URL
* @return string the normalized URL
* @throws InvalidParamException if the parameter is invalid.
*/
public
static
function
createAbsolute
(
$params
)
{
return
static
::
create
(
$params
,
true
);
}
/**
* Prefixes relative URL with base URL
* Prefixes relative URL with base URL
*
*
* @param string $url relative URL
* @param string $url relative URL
...
...
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