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
be5afe7d
Commit
be5afe7d
authored
Dec 22, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1572: Added `yii\web\Controller::createAbsoluteUrl()`
parent
a7cf6a98
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
7 deletions
+53
-7
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Controller.php
framework/yii/web/Controller.php
+52
-7
No files found.
framework/CHANGELOG.md
View file @
be5afe7d
...
...
@@ -24,6 +24,7 @@ Yii Framework 2 Change Log
-
Enh #1469: ActiveRecord::find() now works with default conditions (default scope) applied by createQuery (cebe)
-
Enh #1523: Query conditions now allow to use the NOT operator (cebe)
-
Enh #1552: It is now possible to use multiple bootstrap NavBar in a single page (Alex-Code)
-
Enh #1572: Added
`yii\web\Controller::createAbsoluteUrl()`
(samdark)
-
Enh #1579: throw exception when the given AR relation name does not match in a case sensitive manner (qiangxue)
-
Enh: Added
`favicon.ico`
and
`robots.txt`
to defauly application templates (samdark)
-
Enh: Added
`Widget::autoIdPrefix`
to support prefixing automatically generated widget IDs (qiangxue)
...
...
framework/yii/web/Controller.php
View file @
be5afe7d
...
...
@@ -101,9 +101,9 @@ class Controller extends \yii\base\Controller
}
/**
* Creates a URL using the given route and parameters.
* Normalizes route making it suitable for UrlManager. Absolute routes are staying as is
* while relative routes are converted to absolute routes.
*
* This method enhances [[UrlManager::createUrl()]] by supporting relative routes.
* A relative route is a route without a leading slash, such as "view", "post/view".
*
* - If the route is an empty string, the current [[route]] will be used;
...
...
@@ -112,13 +112,10 @@ class Controller extends \yii\base\Controller
* - 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
* @return string the created URL
* @return string normalized route suitable for UrlManager
*/
p
ublic
function
createUrl
(
$route
,
$params
=
[]
)
p
rotected
function
getNormalizedRoute
(
$route
)
{
if
(
strpos
(
$route
,
'/'
)
===
false
)
{
// empty or an action ID
...
...
@@ -127,10 +124,58 @@ class Controller extends \yii\base\Controller
// relative to module
$route
=
ltrim
(
$this
->
module
->
getUniqueId
()
.
'/'
.
$route
,
'/'
);
}
return
$route
;
}
/**
* Creates a relative URL using the given route and parameters.
*
* This method enhances [[UrlManager::createUrl()]] by supporting relative routes.
* A relative route is a route without a leading slash, such as "view", "post/view".
*
* - 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
* @return string the created relative URL
*/
public
function
createUrl
(
$route
,
$params
=
[])
{
$route
=
$this
->
getNormalizedRoute
(
$route
);
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
}
/**
* Creates an absolute URL using the given route and parameters.
*
* This method enhances [[UrlManager::createAbsoluteUrl()]] by supporting relative routes.
* A relative route is a route without a leading slash, such as "view", "post/view".
*
* - 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
* @return string the created absolute URL
*/
public
function
createAbsoluteUrl
(
$route
,
$params
=
[])
{
$route
=
$this
->
getNormalizedRoute
(
$route
);
return
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$route
,
$params
);
}
/**
* Returns the canonical URL of the currently requested page.
* The canonical URL is constructed using [[route]] and [[actionParams]]. You may use the following code
* in the layout view to add a link tag about canonical 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