Class yii\web\UrlNormalizer
继承 | yii\web\UrlNormalizer » yii\base\BaseObject |
---|---|
实现 | yii\base\Configurable |
可用版本自 | 2.0.10 |
源码 | https://github.com/yiichina/yii2/blob/api/framework/web/UrlNormalizer.php |
UrlNormalizer normalizes URLs for yii\web\UrlManager and yii\web\UrlRule.
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
$action | integer|callable|null | Action to perform during route normalization. | yii\web\UrlNormalizer |
$collapseSlashes | boolean | Whether slashes should be collapsed, for example site///index will be
converted into site/index |
yii\web\UrlNormalizer |
$normalizeTrailingSlash | boolean | Whether trailing slash should be normalized according to the suffix settings of the rule | yii\web\UrlNormalizer |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\BaseObject |
__construct() | Constructor. | yii\base\BaseObject |
__get() | Returns the value of an object property. | yii\base\BaseObject |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() | Sets value of an object property. | yii\base\BaseObject |
__unset() | Sets an object property to null. | yii\base\BaseObject |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() | Initializes the object. | yii\base\BaseObject |
normalizePathInfo() | Normalizes specified pathInfo. | yii\web\UrlNormalizer |
normalizeRoute() | Performs normalization action for the specified $route. | yii\web\UrlNormalizer |
受保护的方法
方法 | 描述 | 被定义在 |
---|---|---|
collapseSlashes() | Collapse consecutive slashes in $pathInfo, for example converts site///index into site/index . |
yii\web\UrlNormalizer |
normalizeTrailingSlash() | Adds or removes trailing slashes from $pathInfo depending on whether the $suffix has a trailing slash or not. | yii\web\UrlNormalizer |
常量
常量 | 值 | 描述 | 被定义在 |
---|---|---|---|
ACTION_NOT_FOUND | 404 | Represents showing 404 error page during route normalization. | yii\web\UrlNormalizer |
ACTION_REDIRECT_PERMANENT | 301 | Represents permament redirection during route normalization. | yii\web\UrlNormalizer |
ACTION_REDIRECT_TEMPORARY | 302 | Represents temporary redirection during route normalization. | yii\web\UrlNormalizer |
属性详情
Action to perform during route normalization. Available options are:
null
- no special action will be performed301
- the request should be redirected to the normalized URL using permanent redirection302
- the request should be redirected to the normalized URL using temporary redirection404
- yii\web\NotFoundHttpException will be throwncallable
- custom user callback, for example:function ($route, $normalizer) { // use custom action for redirections $route[1]['oldRoute'] = $route[0]; $route[0] = 'site/redirect'; return $route; }
Whether slashes should be collapsed, for example site///index
will be
converted into site/index
Whether trailing slash should be normalized according to the suffix settings of the rule
方法详情
Collapse consecutive slashes in $pathInfo, for example converts site///index
into site/index
.
protected string collapseSlashes($pathInfo) | ||
$pathInfo | string | Raw path info. |
return | string | Normalized path info. |
---|
Normalizes specified pathInfo.
public string normalizePathInfo($pathInfo, $suffix, &$normalized = false) | ||
$pathInfo | string | PathInfo for normalization |
$suffix | string | Current rule suffix |
$normalized | boolean | If specified, this variable will be set to |
return | string | Normalized pathInfo |
---|
Performs normalization action for the specified $route.
public array normalizeRoute($route) | ||
$route | array | Route for normalization |
return | array | Normalized route |
---|---|---|
throws | yii\base\InvalidConfigException | if invalid normalization action is used. |
throws | yii\web\UrlNormalizerRedirectException | if normalization requires redirection. |
throws | yii\web\NotFoundHttpException | if normalization suggests action matching route does not exist. |
Adds or removes trailing slashes from $pathInfo depending on whether the $suffix has a trailing slash or not.
protected string normalizeTrailingSlash($pathInfo, $suffix) | ||
$pathInfo | string | Raw path info. |
$suffix | string | |
return | string | Normalized path info. |
---|