没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Class yii\web\UrlRule

继承yii\web\UrlRule » yii\base\BaseObject
实现yii\base\Configurable, yii\web\UrlRuleInterface
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/framework/web/UrlRule.php

UrlRule represents a rule used by yii\web\UrlManager for parsing and generating URLs.

To define your own URL parsing and creation logic you can extend from this class and add it to yii\web\UrlManager::$rules like this:

'rules' => [
    ['class' => 'MyUrlRule', 'pattern' => '...', 'route' => 'site/index', ...],
    // ...
]

公共属性

隐藏继承的属性

属性类型描述被定义在
$createUrlStatus null|integer Status of the URL creation after the last createUrl() call. yii\web\UrlRule
$defaults array The default GET parameters (name => value) that this rule provides. yii\web\UrlRule
$encodeParams boolean A value indicating if parameters should be url encoded. yii\web\UrlRule
$host string The pattern used to parse and create the host info part of a URL (e.g. `http://example. yii\web\UrlRule
$mode integer A value indicating if this rule should be used for both request parsing and URL creation, parsing only, or creation only. yii\web\UrlRule
$name string The name of this rule. yii\web\UrlRule
$normalizer yii\web\UrlNormalizer|array|false|null The configuration for yii\web\UrlNormalizer used by this rule. yii\web\UrlRule
$pattern string The pattern used to parse and create the path info part of a URL. yii\web\UrlRule
$route string The route to the controller action yii\web\UrlRule
$suffix string The URL suffix used for this rule. yii\web\UrlRule
$verb string|array The HTTP verb (e.g. GET, POST, DELETE) that this rule should match. yii\web\UrlRule

受保护的属性

隐藏继承的属性

属性类型描述被定义在
$createStatus integer|null Status of the URL creation after the last createUrl() call. yii\web\UrlRule
$placeholders array List of placeholders for matching parameters names. yii\web\UrlRule

公共方法

隐藏继承的方法

方法描述被定义在
__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
__toString() yii\web\UrlRule
__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
createUrl() Creates a URL according to the given route and parameters. yii\web\UrlRule
getCreateUrlStatus() Returns status of the URL creation after the last createUrl() call. yii\web\UrlRule
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 this rule. yii\web\UrlRule
parseRequest() Parses the given request and returns the corresponding route and parameters. yii\web\UrlRule

受保护的方法

隐藏继承的方法

方法描述被定义在
getNormalizer() yii\web\UrlRule
getParamRules() Returns list of regex for matching parameter. yii\web\UrlRule
hasNormalizer() yii\web\UrlRule
substitutePlaceholderNames() Iterates over $placeholders and checks whether each placeholder exists as a key in $matches array. yii\web\UrlRule

常量

隐藏继承的常量

常量描述被定义在
CREATE_STATUS_PARAMS_MISMATCH 4 Represents the unsuccessful URL generation by last createUrl() call, because of mismatched or missing parameters. yii\web\UrlRule
CREATE_STATUS_PARSING_ONLY 1 Represents the unsuccessful URL generation by last createUrl() call, because rule does not support creating URLs. yii\web\UrlRule
CREATE_STATUS_ROUTE_MISMATCH 2 Represents the unsuccessful URL generation by last createUrl() call, because of mismatched route. yii\web\UrlRule
CREATE_STATUS_SUCCESS 0 Represents the successful URL generation by last createUrl() call. yii\web\UrlRule
CREATION_ONLY 2 Set $mode with this value to mark that this rule is for URL creation only. yii\web\UrlRule
PARSING_ONLY 1 Set $mode with this value to mark that this rule is for URL parsing only. yii\web\UrlRule

属性详情

$createStatus 受保护 属性 (自版本 2.0.12 可用)

Status of the URL creation after the last createUrl() call.

protected integer|null $createStatus null
$createUrlStatus 公共 只读 属性

Status of the URL creation after the last createUrl() call. null if rule does not provide info about create status.

$defaults 公共 属性

The default GET parameters (name => value) that this rule provides. When this rule is used to parse the incoming request, the values declared in this property will be injected into $_GET.

public array $defaults = []
$encodeParams 公共 属性

A value indicating if parameters should be url encoded.

public boolean $encodeParams true
$host 公共 属性

The pattern used to parse and create the host info part of a URL (e.g. http://example.com).

参见 $pattern.

public string $host null
$mode 公共 属性

A value indicating if this rule should be used for both request parsing and URL creation, parsing only, or creation only. If not set or 0, it means the rule is both request parsing and URL creation. If it is PARSING_ONLY, the rule is for request parsing only. If it is CREATION_ONLY, the rule is for URL creation only.

public integer $mode null
$name 公共 属性

The name of this rule. If not set, it will use $pattern as the name.

public string $name null
$normalizer 公共 属性 (自版本 2.0.10 可用)

The configuration for yii\web\UrlNormalizer used by this rule. If null, yii\web\UrlManager::$normalizer will be used, if false, normalization will be skipped for this rule.

$pattern 公共 属性

The pattern used to parse and create the path info part of a URL.

参见:

public string $pattern null
$placeholders 受保护 属性 (自版本 2.0.7 可用)

List of placeholders for matching parameters names. Used in parseRequest(), createUrl(). On the rule initialization, the $pattern parameters names will be replaced with placeholders. This array contains relations between the original parameters names and their placeholders. The array keys are the placeholders and the values are the original names.

参见:

protected array $placeholders = []
$route 公共 属性

The route to the controller action

public string $route null
$suffix 公共 属性

The URL suffix used for this rule. For example, ".html" can be used so that the URL looks like pointing to a static HTML page. If not set, the value of yii\web\UrlManager::$suffix will be used.

public string $suffix null
$verb 公共 属性

The HTTP verb (e.g. GET, POST, DELETE) that this rule should match. Use array to represent multiple verbs that this rule may match. If this property is not set, the rule can match any verb. Note that this property is only used when parsing a request. It is ignored for URL creation.

public string|array $verb null

方法详情

__toString() 公共 方法 (自版本 2.0.11 可用)

public string __toString()
createUrl() 公共 方法

Creates a URL according to the given route and parameters.

public string|boolean createUrl($manager, $route, $params)
$manager yii\web\UrlManager

The URL manager

$route string

The route. It should not have slashes at the beginning or the end.

$params array

The parameters

return string|boolean

The created URL, or false if this rule cannot be used for creating this URL.

getCreateUrlStatus() 公共 方法 (自版本 2.0.12 可用)

Returns status of the URL creation after the last createUrl() call.

参见 $createStatus.

public null|integer getCreateUrlStatus()
return null|integer

Status of the URL creation after the last createUrl() call. null if rule does not provide info about create status.

getNormalizer() 受保护 方法 (自版本 2.0.10 可用)

protected yii\web\UrlNormalizer|null getNormalizer($manager)
$manager yii\web\UrlManager

The URL manager

getParamRules() 受保护 方法 (自版本 2.0.6 可用)

Returns list of regex for matching parameter.

protected array getParamRules()
return array

Parameter keys and regexp rules.

hasNormalizer() 受保护 方法 (自版本 2.0.10 可用)

protected boolean hasNormalizer($manager)
$manager yii\web\UrlManager

The URL manager

init() 公共 方法

Initializes this rule.

public void init()
parseRequest() 公共 方法

Parses the given request and returns the corresponding route and parameters.

public array|boolean parseRequest($manager, $request)
$manager yii\web\UrlManager

The URL manager

$request yii\web\Request

The request component

return array|boolean

The parsing result. The route and the parameters are returned as an array. If false, it means this rule cannot be used to parse this path info.

substitutePlaceholderNames() 受保护 方法 (自版本 2.0.7 可用)

Iterates over $placeholders and checks whether each placeholder exists as a key in $matches array.

When found - replaces this placeholder key with a appropriate name of matching parameter. Used in parseRequest(), createUrl().

参见 $placeholders.

protected array substitutePlaceholderNames(array $matches)
$matches array

Result of preg_match() call

return array

Input array with replaced placeholder keys