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
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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.

보호된 프로퍼티들

프로퍼티 타입 설명
$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