Property |
Type |
Description |
|
$cache |
|
the cache object or the application component ID of the cache object.
Compiled URL rules will be cached through this cache object, if it is available.
After the UrlManager object is created, if you want to change this property,
you should only assign it with a cache object.
Set this property to false if you do not want to cache the URL rules. |
|
$enablePrettyUrl |
|
whether to enable pretty URLs. Instead of putting all parameters in the query
string part of a URL, pretty URLs allow using path info to represent some of the parameters
and can thus produce more user-friendly URLs, such as "/news/Yii-is-released", instead of
"/index.php?r=news%2Fview&id=100". |
|
$enableStrictParsing |
|
whether to enable strict parsing. If strict parsing is enabled, the incoming
requested URL must match at least one of the [[rules]] in order to be treated as a valid request.
Otherwise, the path info part of the request will be treated as the requested route.
This property is used only when [[enablePrettyUrl]] is true. |
|
$normalizer |
|
the configuration for UrlNormalizer used by this UrlManager.
The default value is false, which means normalization will be skipped.
If you wish to enable URL normalization, you should configure this property manually.
For example:
php
[
'class' => 'yii\web\UrlNormalizer',
'collapseSlashes' => true,
'normalizeTrailingSlash' => true,
]
|
|
$routeParam |
|
the GET parameter name for route. This property is used only if [[enablePrettyUrl]] is false. |
|
$ruleConfig |
|
the default configuration of URL rules. Individual rule configurations
specified via [[rules]] will take precedence when the same property of the rule is configured. |
|
$rules |
|
the rules for creating and parsing URLs when [[enablePrettyUrl]] is true.
This property is used only if [[enablePrettyUrl]] is true. Each element in the array
is the configuration array for creating a single URL rule. The configuration will
be merged with [[ruleConfig]] first before it is used for creating the rule object.
A special shortcut format can be used if a rule only specifies [[UrlRule::pattern|pattern]]
and [[UrlRule::route|route]]: 'pattern' => 'route'. That is, instead of using a configuration
array, one can use the key to represent the pattern and the value the corresponding route.
For example, 'post/' => 'post/view'.
For RESTful routing the mentioned shortcut format also allows you to specify the
[[UrlRule::verb|HTTP verb]] that the rule should apply for.
You can do that by prepending it to the pattern, separated by space.
For example, 'PUT post/' => 'post/update'.
You may specify multiple verbs by separating them with comma
like this: 'POST,PUT post/index' => 'post/create'.
The supported verbs in the shortcut format are: GET, HEAD, POST, PUT, PATCH and DELETE.
Note that [[UrlRule::mode|mode]] will be set to PARSING_ONLY when specifying verb in this way
so you normally would not specify a verb for normal GET request.
Here is an example configuration for RESTful CRUD controller:
php
[
'dashboard' => 'site/index',
'POST s' => '/create',
's' => '/index',
'PUT /' => '/update',
'DELETE /' => '/delete',
'/' => '/view',
];
Note that if you modify this property after the UrlManager object is created, make sure
you populate the array with rule objects instead of rule configurations. |
|
$showScriptName |
|
whether to show entry script name in the constructed URL. Defaults to true.
This property is used only if [[enablePrettyUrl]] is true. |
|
$suffix |
|
the URL suffix used when [[enablePrettyUrl]] is true.
For example, ".html" can be used so that the URL looks like pointing to a static HTML page.
This property is used only if [[enablePrettyUrl]] is true. |
|