# CompositeUrlRule

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

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [web](/docs/api/yii/web/index.md) › CompositeUrlRule

| abstract class | `yii\web\CompositeUrlRule` |
| --- | --- |
| Extends | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`UrlRuleInterface`](/docs/api/yii/web/urlruleinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/web/CompositeUrlRule.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/web/CompositeUrlRule.php#L23) |

2 subclasses:

- [`yii\rest\UrlRule`](/docs/api/yii/rest/urlrule/index.md)
- [`GroupUrlRule`](/docs/api/yii/web/groupurlrule/index.md)

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

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-createUrlStatus"></span>`$createUrlStatus` read-only | `int\|null` | Status of the URL creation after the last [`createUrl()`](/docs/api/yii/web/compositeurlrule/index.md#method-createUrl) call. `null` if rule does not provide info about create status. | `CompositeUrlRule` |
| <span id="property-createStatus"></span>`$createStatus` protected | `int\|null` | Status of the URL creation after the last [`createUrl()`](/docs/api/yii/web/compositeurlrule/index.md#method-createUrl) call. Default: `null`. Available since 2.0.12. | `CompositeUrlRule` |
| [`$rules`](#property-rules) protected | [`UrlRuleInterface`](/docs/api/yii/web/urlruleinterface/index.md)`[]\|`[`UrlRuleInterface`](/docs/api/yii/web/urlruleinterface/index.md)`[][]\|array[]\|string[]` | The URL rules contained in this composite rule. Default: `[]`. | `CompositeUrlRule` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`createUrl()`](#method-createUrl) | Creates a URL according to the given route and parameters. | `CompositeUrlRule` |
| [`getCreateUrlStatus()`](#method-getCreateUrlStatus) | Returns status of the URL creation after the last [`createUrl()`](/docs/api/yii/web/compositeurlrule/index.md#method-createUrl) call. | `CompositeUrlRule` |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`init()`](#method-init) | Initializes the object. | `CompositeUrlRule` |
| [`parseRequest()`](#method-parseRequest) | Parses the given request and returns the corresponding route and parameters. | `CompositeUrlRule` |
| [`createRules()`](#method-createRules) protected abstract | Creates the URL rules that should be contained within this composite rule. | `CompositeUrlRule` |
| [`iterateRules()`](#method-iterateRules) protected | Iterates through specified rules and calls [`createUrl()`](/docs/api/yii/web/compositeurlrule/index.md#method-createUrl) for each of them. | `CompositeUrlRule` |

## Property details

### $rules <span id="property-rules"></span>

```php
protected yii\web\UrlRuleInterface[]|yii\web\UrlRuleInterface[][]|array[]|string[] $rules = []
```

The URL rules contained in this composite rule.

This property is set in [`init()`](/docs/api/yii/web/compositeurlrule/index.md#method-init) by the return value of [`createRules()`](/docs/api/yii/web/compositeurlrule/index.md#method-createRules).

## Method details

### createUrl() <span id="method-createUrl"></span>

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

Creates a URL according to the given route and parameters.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$manager` | `mixed` | The URL manager |
| `$route` | `mixed` | The route. It should not have slashes at the beginning or the end. |
| `$params` | `mixed` | The parameters |

**Returns**

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

### getCreateUrlStatus() <span id="method-getCreateUrlStatus"></span>

```php
public function getCreateUrlStatus(): int|null
```

Returns status of the URL creation after the last [`createUrl()`](/docs/api/yii/web/compositeurlrule/index.md#method-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()`](/docs/api/yii/web/compositeurlrule/index.md#method-createUrl) call. `null` if rule does not provide info about create status.

**Since**

2.0.12

**See also**

- [`$createStatus`](/docs/api/yii/web/compositeurlrule/index.md#property-createStatus)
- <https://www.php.net/manual/en/language.operators.bitwise.php>

### init() <span id="method-init"></span>

```php
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`

### parseRequest() <span id="method-parseRequest"></span>

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

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$manager` | `mixed` | The URL manager |
| `$request` | `mixed` | The 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.

### createRules() <span id="method-createRules"></span>

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

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

**Returns**

[`UrlRuleInterface`](/docs/api/yii/web/urlruleinterface/index.md)`[]|`[`UrlRuleInterface`](/docs/api/yii/web/urlruleinterface/index.md)`[][]`: The URL rules

### iterateRules() <span id="method-iterateRules"></span>

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

Iterates through specified rules and calls [`createUrl()`](/docs/api/yii/web/compositeurlrule/index.md#method-createUrl) for each of them.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rules` | [`UrlRuleInterface`](/docs/api/yii/web/urlruleinterface/index.md)`[]` | Rules to iterate. |
| `$manager` | [`UrlManager`](/docs/api/yii/web/urlmanager/index.md) | The URL manager |
| `$route` | `string` | The route. It should not have slashes at the beginning or the end. |
| `$params` | `array` | The 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**

- [`createUrl()`](/docs/api/yii/web/compositeurlrule/index.md#method-createUrl)