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
9c7e4e51
Commit
9c7e4e51
authored
Jan 11, 2015
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #6697: Added `yii\helpers\Url::current()` method that allows adding or…
Fixes #6697: Added `yii\helpers\Url::current()` method that allows adding or removing parameters from current URL
parent
e4cf948c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
0 deletions
+35
-0
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
BaseUrl.php
framework/helpers/BaseUrl.php
+23
-0
UrlTest.php
tests/unit/framework/helpers/UrlTest.php
+11
-0
No files found.
framework/CHANGELOG.md
View file @
9c7e4e51
...
...
@@ -28,6 +28,7 @@ Yii Framework 2 Change Log
-
Enh #6467:
`ActiveForm`
will scroll to the nearest visible element when the first error input is hidden (newartix)
-
Enh #6488: Support changing
`yii\base\Theme::basePath`
during runtime (qiangxue)
-
Enh #6618: Added Model::addErrors() (slavcodev, pana1990)
-
Enh #6697: Added
`yii\helpers\Url::current()`
method that allows adding or removing parameters from current URL (samdark, callmez)
-
Enh #6739: Log
`Target`
now works also when there is no
`Yii::$app`
instance available, no message prefix will be added in this case (schmunk42)
-
Enh #6748: Improved HTML to Text converter in BaseMailer to generate more readable and correct text version of emails (cebe)
-
Chg #5690: adjusted paths in message config generated by
`yii message/config`
to reflect directory structure better (mikehaertl, samdark)
...
...
framework/helpers/BaseUrl.php
View file @
9c7e4e51
...
...
@@ -342,4 +342,27 @@ class BaseUrl
{
return
strncmp
(
$url
,
'//'
,
2
)
&&
strpos
(
$url
,
'://'
)
===
false
;
}
/**
* Creates URL from the current one by adding parameters specified.
*
* @param array $params associative array of parameters. If value is null, parameter will be removed.
* @param boolean|string $scheme the URI scheme to use in the generated URL:
*
* - `false` (default): generating a relative URL.
* - `true`: returning an absolute base URL whose scheme is the same as that in [[\yii\web\UrlManager::hostInfo]].
* - string: generating an absolute URL with the specified scheme (either `http` or `https`).
*
* @return string the generated URL
*
* @since 2.0.2
*/
public
static
function
current
(
array
$params
=
[],
$scheme
=
false
)
{
$currentParms
=
Yii
::
$app
->
controller
->
actionParams
;
$currentParms
[
0
]
=
Yii
::
$app
->
controller
->
getRoute
();
$route
=
ArrayHelper
::
merge
(
$currentParms
,
$params
);
return
static
::
toRoute
(
$route
,
$scheme
);
}
}
tests/unit/framework/helpers/UrlTest.php
View file @
9c7e4e51
...
...
@@ -94,6 +94,17 @@ class UrlTest extends TestCase
Url
::
toRoute
(
'site/view'
);
}
public
function
testCurrent
()
{
$this
->
mockAction
(
'page'
,
'view'
,
null
,
[
'id'
=>
10
,
'name'
=>
'test'
]);
$this
->
assertEquals
(
'/base/index.php?r=page%2Fview&id=10&name=test'
,
Url
::
current
());
$this
->
assertEquals
(
'/base/index.php?r=page%2Fview&id=20&name=test'
,
Url
::
current
([
'id'
=>
20
]));
$this
->
assertEquals
(
'/base/index.php?r=page%2Fview&name=test'
,
Url
::
current
([
'id'
=>
null
]));
}
public
function
testTo
()
{
// is an array: the first array element is considered a route, while the rest of the name-value
...
...
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