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
d1212bc7
Commit
d1212bc7
authored
Jul 24, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support relative route in Controller::createUrl()
parent
5c020383
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
Controller.php
framework/yii/web/Controller.php
+12
-5
No files found.
framework/yii/web/Controller.php
View file @
d1212bc7
...
...
@@ -65,11 +65,15 @@ class Controller extends \yii\base\Controller
* Creates a URL using the given route and parameters.
*
* This method enhances [[UrlManager::createUrl()]] by supporting relative routes.
* A relative route is a route without a slash, such as "view". If the route is an empty
* string, [[route]] will be used; Otherwise, [[uniqueId]] will be prepended to a relative route.
* A relative route is a route without a leading slash, such as "view", "post/view".
*
* After this route conversion, the method This method calls [[UrlManager::createUrl()]]
* to create a URL.
* - If the route is an empty string, the current [[route]] will be used;
* - 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 [[uniqueId]];
* - If the route has no leading slash, it is considered to be a route relative
* to the current module and will be prepended with the module's uniqueId.
*
* After this route conversion, the method calls [[UrlManager::createUrl()]] to create a URL.
*
* @param string $route the route. This can be either an absolute route or a relative route.
* @param array $params the parameters (name-value pairs) to be included in the generated URL
...
...
@@ -78,8 +82,11 @@ class Controller extends \yii\base\Controller
public
function
createUrl
(
$route
,
$params
=
array
())
{
if
(
strpos
(
$route
,
'/'
)
===
false
)
{
//
a relative route
//
empty or an action ID
$route
=
$route
===
''
?
$this
->
getRoute
()
:
$this
->
getUniqueId
()
.
'/'
.
$route
;
}
elseif
(
$route
[
0
]
!==
'/'
)
{
// relative to module
$route
=
ltrim
(
$this
->
module
->
getUniqueId
()
.
'/'
.
$route
,
'/'
);
}
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
}
...
...
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