PHP Класс yii\web\UrlRule

To define your own URL parsing and creation logic you can extend from this class and add it to [[UrlManager::rules]] like this: ~~~ 'rules' => [ ['class' => 'MyUrlRule', 'pattern' => '...', 'route' => 'site/index', ...], ... ] ~~~
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Object, implements yii\web\UrlRuleInterface
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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.
$encodeParams a value indicating if parameters should be url encoded.
$host the pattern used to parse and create the host info part of a URL (e.g. http://example.com).
$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.
$name the name of this rule. If not set, it will use [[pattern]] as the name.
$normalizer the configuration for UrlNormalizer used by this rule. If null, [[UrlManager::normalizer]] will be used, if false, normalization will be skipped for this rule.
$pattern On the rule initialization, the [[pattern]] matching parameters names will be replaced with [[placeholders]].
$route the route to the controller action
$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, the value of [[UrlManager::suffix]] will be used.
$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.

Защищенные свойства (Protected)

Свойство Тип Описание
$placeholders list of placeholders for matching parameters names. Used in UrlRule::parseRequest, UrlRule::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.

Открытые методы

Метод Описание
createUrl ( UrlManager $manager, string $route, array $params ) : string | boolean Creates a URL according to the given route and parameters.
init ( ) Initializes this rule.
parseRequest ( UrlManager $manager, Request $request ) : array | boolean Parses the given request and returns the corresponding route and parameters.

Защищенные методы

Метод Описание
getNormalizer ( UrlManager $manager ) : UrlNormalizer | null
getParamRules ( ) : array Returns list of regex for matching parameter.
hasNormalizer ( UrlManager $manager ) : boolean
substitutePlaceholderNames ( array $matches ) : array Iterates over [[placeholders]] and checks whether each placeholder exists as a key in $matches array.

Описание методов

createUrl() публичный Метод

Creates a URL according to the given route and parameters.
public createUrl ( UrlManager $manager, string $route, array $params ) : string | boolean
$manager UrlManager the URL manager
$route string the route. It should not have slashes at the beginning or the end.
$params array the parameters
Результат string | boolean the created URL, or `false` if this rule cannot be used for creating this URL.

getNormalizer() защищенный Метод

С версии: 2.0.10
protected getNormalizer ( UrlManager $manager ) : UrlNormalizer | null
$manager UrlManager the URL manager
Результат UrlNormalizer | null

getParamRules() защищенный Метод

Returns list of regex for matching parameter.
С версии: 2.0.6
protected getParamRules ( ) : array
Результат array parameter keys and regexp rules.

hasNormalizer() защищенный Метод

С версии: 2.0.10
protected hasNormalizer ( UrlManager $manager ) : boolean
$manager UrlManager the URL manager
Результат boolean

init() публичный Метод

Initializes this rule.
public init ( )

parseRequest() публичный Метод

Parses the given request and returns the corresponding route and parameters.
public parseRequest ( UrlManager $manager, Request $request ) : array | boolean
$manager UrlManager the URL manager
$request Request the request component
Результат 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() защищенный Метод

When found - replaces this placeholder key with a appropriate name of matching parameter. Used in UrlRule::parseRequest, UrlRule::createUrl.
См. также: placeholders
С версии: 2.0.7
protected substitutePlaceholderNames ( array $matches ) : array
$matches array result of `preg_match()` call
Результат array input array with replaced placeholder keys

Описание свойств

$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 $defaults

$encodeParams публичное свойство

a value indicating if parameters should be url encoded.
public $encodeParams

$host публичное свойство

the pattern used to parse and create the host info part of a URL (e.g. http://example.com).
См. также: pattern
public $host

$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 $mode

$name публичное свойство

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

$normalizer публичное свойство

the configuration for UrlNormalizer used by this rule. If null, [[UrlManager::normalizer]] will be used, if false, normalization will be skipped for this rule.
С версии: 2.0.10
public $normalizer

$pattern публичное свойство

On the rule initialization, the [[pattern]] matching parameters names will be replaced with [[placeholders]].
См. также: host
См. также: placeholders
public $pattern

$placeholders защищенное свойство

list of placeholders for matching parameters names. Used in UrlRule::parseRequest, UrlRule::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.
См. также: parseRequest()
См. также: createUrl()
С версии: 2.0.7
protected $placeholders

$route публичное свойство

the route to the controller action
public $route

$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, the value of [[UrlManager::suffix]] will be used.
public $suffix

$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 $verb