yii\web\UrlManager类,解析和创建url,继承yii\base\Component类。
一、属性
1. $enablePrettyUrl 启用url用户友好化
// 启用url用户友好化
public $enablePrettyUrl = false;
2. $enableStrictParsing 是否启用严格解析
//是否启用严格解析
public $enableStrictParsing = false;
3. $rules 创建和解析url的规则
/**
* @var array 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/<id:\d+>' => '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/<id:\d+>' => '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 <controller:[\w-]+>' => '<controller>/create',
* '<controller:[\w-]+>s' => '<controller>/index',
*
* 'PUT <controller:[\w-]+>/<id:\d+>' => '<controller>/update',
* 'DELETE <controller:[\w-]+>/<id:\d+>' => '<controller>/delete',
* '<controller:[\w-]+>/<id:\d+>' => '<controller>/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.
*/
// 创建和解析url的规则
public $rules = [];
4. $suffix url 后缀,".html,.asp,..."
// url 后缀,".html,.asp,..."
public $suffix;
5. $showScriptName URL中是否显示入口脚本文件名称
//URL中是否显示入口脚本文件名称
public $showScriptName = true;
6. $routeParam 路由的GET参数名
//路由的GET参数名
public $routeParam = 'r';
7. $cache 缓存对象或缓存对象的应用程序组件ID
/**
* @var CacheInterface|array|string|bool the cache object or the application component ID of the cache object.
* This can also be an array that is used to create a [[CacheInterface]] instance in case you do not want to use
* an application component.
* 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` or `null` if you do not want to cache the URL rules.
*
* Cache entries are stored for the time set by [[\yii\caching\Cache::$defaultDuration|$defaultDuration]] in
* the cache configuration, which is unlimited by default. You may want to tune this value if your [[rules]]
* change frequently.
*/
//缓存对象或缓存对象的应用程序组件ID
public $cache = 'cache';
8. $ruleConfig 默认url规则配置
// 默认url规则配置
public $ruleConfig = ['class' => 'yii\web\UrlRule'];
9. $normalizer 是否规范化url
/**
* @var UrlNormalizer|array|string|false 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,
* ]
* ```
*
* @since 2.0.10
*/
// 是否规范化url
public $normalizer = false;
10. 其他属性
// 换成规则的key
protected $cacheKey = __CLASS__;
private $_baseUrl;
private $_scriptUrl;
private $_hostInfo;
private $_ruleCache;