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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
48448864
Commit
48448864
authored
Jan 21, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added schema parameter to createAbsoluteUrl() to force 'http' or 'https'
fixes #1585
parent
ab59a795
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
7 deletions
+21
-7
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Controller.php
framework/web/Controller.php
+4
-2
UrlManager.php
framework/web/UrlManager.php
+9
-5
UrlManagerTest.php
tests/unit/framework/web/UrlManagerTest.php
+7
-0
No files found.
framework/CHANGELOG.md
View file @
48448864
...
...
@@ -59,6 +59,7 @@ Yii Framework 2 Change Log
-
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 #1581: Added
`ActiveQuery::joinWith()`
and
`ActiveQuery::innerJoinWith()`
to support joining with relations (qiangxue)
-
Enh #1585: added schema parameter to createAbsoluteUrl() to force 'http' or 'https' (cebe)
-
Enh #1601: Added support for tagName and encodeLabel parameters in ButtonDropdown (omnilight)
-
Enh #1611: Added
`BaseActiveRecord::markAttributeDirty()`
(qiangxue)
-
Enh #1633: Advanced application template now works with MongoDB by default (samdark)
...
...
framework/web/Controller.php
View file @
48448864
...
...
@@ -167,12 +167,14 @@ class Controller extends \yii\base\Controller
*
* @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
* @param string $schema the schema to use for the url. e.g. 'http' or 'https'. If not specified
* the schema of the current request will be used.
* @return string the created absolute URL
*/
public
function
createAbsoluteUrl
(
$route
,
$params
=
[])
public
function
createAbsoluteUrl
(
$route
,
$params
=
[]
,
$schema
=
null
)
{
$route
=
$this
->
getNormalizedRoute
(
$route
);
return
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$route
,
$params
);
return
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$route
,
$params
,
$schema
);
}
/**
...
...
framework/web/UrlManager.php
View file @
48448864
...
...
@@ -277,17 +277,21 @@ class UrlManager extends Component
* This method prepends the URL created by [[createUrl()]] with the [[hostInfo]].
* @param string $route the route
* @param array $params the parameters (name-value pairs)
* @param string $schema the schema to use for the url. e.g. 'http' or 'https'. If not specified
* the schema of the current request will be used.
* @return string the created URL
* @see createUrl()
*/
public
function
createAbsoluteUrl
(
$route
,
$params
=
[])
public
function
createAbsoluteUrl
(
$route
,
$params
=
[]
,
$schema
=
null
)
{
$url
=
$this
->
createUrl
(
$route
,
$params
);
if
(
strpos
(
$url
,
'://'
)
!==
false
)
{
return
$url
;
}
else
{
return
$this
->
getHostInfo
()
.
$url
;
if
(
strpos
(
$url
,
'://'
)
===
false
)
{
$url
=
$this
->
getHostInfo
(
$schema
)
.
$url
;
}
if
(
$schema
!==
null
&&
(
$pos
=
strpos
(
$url
,
'://'
))
!==
false
)
{
$url
=
$schema
.
substr
(
$url
,
$pos
);
}
return
$url
;
}
/**
...
...
tests/unit/framework/web/UrlManagerTest.php
View file @
48448864
...
...
@@ -124,6 +124,13 @@ class UrlManagerTest extends TestCase
]);
$url
=
$manager
->
createAbsoluteUrl
(
'post/view'
,
[
'id'
=>
1
,
'title'
=>
'sample post'
]);
$this
->
assertEquals
(
'http://www.example.com?r=post/view&id=1&title=sample+post'
,
$url
);
$url
=
$manager
->
createAbsoluteUrl
(
'post/view'
,
[
'id'
=>
1
,
'title'
=>
'sample post'
],
'https'
);
$this
->
assertEquals
(
'https://www.example.com?r=post/view&id=1&title=sample+post'
,
$url
);
$manager
->
hostInfo
=
'https://www.example.com'
;
$url
=
$manager
->
createAbsoluteUrl
(
'post/view'
,
[
'id'
=>
1
,
'title'
=>
'sample post'
],
'http'
);
$this
->
assertEquals
(
'http://www.example.com?r=post/view&id=1&title=sample+post'
,
$url
);
}
public
function
testParseRequest
()
...
...
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