Download the PHP package djidji/yii2-default-url-rule without Composer
On this page you can find all versions of the php package djidji/yii2-default-url-rule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download djidji/yii2-default-url-rule
More information about djidji/yii2-default-url-rule
Files in djidji/yii2-default-url-rule
Package yii2-default-url-rule
Short Description Parsing and creating url with arguments pretified as well instead of in query string format
License BSD-3-Clause
Informations about the package yii2-default-url-rule
UrlRule for default basic logic in parsing and creating pretty Url.
Parsing and creating url with arguments pretified as well instead of in query string format. Route and argument segments of url are separated by the UrlManager->routeParam
Conventions
-
Argument is prettified only if its name is declared as action method parameter otherwise it stay in query string format;
-
Arguments are orderer by the way corresponding action method parameters are declared;
-
Optional Argument nth binds to its corresponding action method parameter only if all arguments --nth are explicitly passed. --nth argments are inserted at their respective places in created url if were nor explicit;
- Arguments less than required or more than action method parameters show 404
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by declaring in rules of Urlmanager :
Examples
To create Url
-
Url::to(['post/index', 'year' => 2014, 'category' => 'php'])
creates/index.php/post/index/r/php/2014
; -
Url::to(['post/index', 'category' => 'php'])
creates/index.php/post/index/r/php
; -
Url::to(['post/index', 'category' => 'php','tag'=>'programming'])
creates/index.php/post/index/r/php/2015/programming
. default value of parameter 'year' is inserted at its place; -
Url::to(['post/index','year' => 2014])
result tofalse
because the argument for required$category
parameter is not passed; -
Url::to(['post/view', 'id' => 100])
creates/index.php/post/view/r/100
; Url::to(['post/view', 'id' => 100, 'source' => 'ad'])
createscreates /index.php/post/view/r/100?source=ad
. Because "source" argument is not declared as actionView methoth, it is appended as a query parameter in the created URL.
To parse Url
-
/index.php/post/index
result tofalse
because actionIndex has required firs parameter that need argments to be passed. -
/index.php/post/index/r/php
is parsed to['post/index', ['category' => 'php']]
; -
/index.php/post/index/r/php/2015/programming
is parsed to['post/index', ['category' => 'php','tag'=>'programming','year'=>2015]]
; -
/index.php/post/index/r/php/programming
is parsed to['post/index', ['category' => 'php','year'=>'programming']]
; -
/index.php/post/view/r/100?source=ad
is parsed to['post/view', ['id' => 100]]
; /index.php/post/view/r/100/ad?source=ad
result tofalse
because actionView method expect one argment instead of two.