Skip to content
PHP Ecosystem
Explore

CompositeUrlRule

API reference › yii › web › CompositeUrlRule

abstract classyii\web\CompositeUrlRule
Extendsyii\base\BaseObject
ImplementsUrlRuleInterface, yii\base\Configurable
Since2.0
Sourceframework/web/CompositeUrlRule.php
2 subclasses

CompositeUrlRule is the base class for URL rule classes that consist of multiple simpler rules.

PropertyTypeDescriptionDefined by
$createUrlStatus read-onlyint|nullStatus of the URL creation after the last createUrl() call. null if rule does not provide info about create status.CompositeUrlRule
$createStatus protectedint|nullStatus of the URL creation after the last createUrl() call. Default: null. Available since 2.0.12.CompositeUrlRule
$rules protectedUrlRuleInterface[]|UrlRuleInterface[][]|array[]|string[]The URL rules contained in this composite rule. Default: [].CompositeUrlRule
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.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() staticReturns the fully qualified name of this class.yii\base\BaseObject
createUrl()Creates a URL according to the given route and parameters.CompositeUrlRule
getCreateUrlStatus()Returns status of the URL creation after the last createUrl() call.CompositeUrlRule
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.CompositeUrlRule
parseRequest()Parses the given request and returns the corresponding route and parameters.CompositeUrlRule
createRules() protected abstractCreates the URL rules that should be contained within this composite rule.CompositeUrlRule
iterateRules() protectedIterates through specified rules and calls createUrl() for each of them.CompositeUrlRule
protected yii\web\UrlRuleInterface[]|yii\web\UrlRuleInterface[][]|array[]|string[] $rules = []

The URL rules contained in this composite rule.

This property is set in init() by the return value of createRules().

public function createUrl(mixed $manager, mixed $route, mixed $params): string|bool

Creates a URL according to the given route and parameters.

Parameters

ParameterTypeDescription
$managermixedThe URL manager
$routemixedThe route. It should not have slashes at the beginning or the end.
$paramsmixedThe parameters

Returns

string|bool: The created URL, or false if this rule cannot be used for creating this URL.

public function getCreateUrlStatus(): int|null

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

For multiple rules statuses will be combined by bitwise or operator (e.g. UrlRule::CREATE_STATUS_PARSING_ONLY | UrlRule::CREATE_STATUS_PARAMS_MISMATCH).

Returns

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

Since

2.0.12

See also

public function init(): mixed

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

Returns

mixed

public function parseRequest(mixed $manager, mixed $request): array|bool

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

Parameters

ParameterTypeDescription
$managermixedThe URL manager
$requestmixedThe request component

Returns

array|bool: 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.

abstract protected function createRules(): yii\web\UrlRuleInterface[]|yii\web\UrlRuleInterface[][]

Creates the URL rules that should be contained within this composite rule.

Returns

UrlRuleInterface[]|UrlRuleInterface[][]: The URL rules

protected function iterateRules(yii\web\UrlRuleInterface[] $rules, yii\web\UrlManager $manager, string $route, array $params): bool|string

Iterates through specified rules and calls createUrl() for each of them.

Parameters

ParameterTypeDescription
$rulesUrlRuleInterface[]Rules to iterate.
$managerUrlManagerThe URL manager
$routestringThe route. It should not have slashes at the beginning or the end.
$paramsarrayThe parameters

Returns

bool|string: The created URL, or false if none of specified rules cannot be used for creating this URL.

Since

2.0.12

See also