current() public static method (available since version 2.0.3)
Creates a URL by using the current route and the GET parameters.
You may modify or remove some of the GET parameters, or add additional query parameters through the $params
parameter. In particular, if you specify a parameter to be null, then this parameter will be removed from the existing GET parameters; all other parameters specified in $params
will be merged with the existing GET parameters. For example,
// assume $_GET = ['id' => 123, 'src' => 'google'], current route is "post/view" // /index.php?r=post%2Fview&id=123&src=google echo Url::current(); // /index.php?r=post%2Fview&id=123 echo Url::current(['src' => null]); // /index.php?r=post%2Fview&id=100&src=google echo Url::current(['id' => 100]);
Note that if you're replacing array parameters with []
at the end you should specify $params
as nested arrays. For a PostSearchForm
model where parameter names are PostSearchForm[id]
and PostSearchForm[src]
the syntax would be the following:
// index.php?r=post%2Findex&PostSearchForm%5Bid%5D=100&PostSearchForm%5Bsrc%5D=google echo Url::current([ $postSearch->formName() => ['id' => 100, 'src' => 'google'], ]);
public static string current ( array $params = [], $scheme = false ) | ||
---|---|---|
$params | array |
An associative array of parameters that will be merged with the current GET parameters. If a parameter value is null, the corresponding GET parameter will be removed. |
$scheme | boolean|string |
The URI scheme to use in the generated URL:
|
return | string |
The generated URL |
Please login to continue.