Class yii\web\GroupUrlRule

Inheritanceyii\web\GroupUrlRule » yii\web\CompositeUrlRule » yii\base\BaseObject
Implementsyii\base\Configurable, yii\web\UrlRuleInterface
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/web/GroupUrlRule.php

GroupUrlRule represents a collection of URL rules sharing the same prefix in their patterns and routes.

GroupUrlRule is best used by a module which often uses module ID as the prefix for the URL rules. For example, the following code creates a rule for the admin module:

new GroupUrlRule([
    'prefix' => 'admin',
    'rules' => [
        'login' => 'user/login',
        'logout' => 'user/logout',
        'dashboard' => 'default/dashboard',
    ],
]);

// the above rule is equivalent to the following three rules:

[
    'admin/login' => 'admin/user/login',
    'admin/logout' => 'admin/user/logout',
    'admin/dashboard' => 'admin/default/dashboard',
]

The above example assumes the prefix for patterns and routes are the same. They can be made different by configuring $prefix and $routePrefix separately.

Using a GroupUrlRule is more efficient than directly declaring the individual rules it contains. This is because GroupUrlRule can quickly determine if it should process a URL parsing or creation request by simply checking if the prefix matches.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$prefix string The prefix for the pattern part of every rule declared in $rules. yii\web\GroupUrlRule
$routePrefix string The prefix for the route part of every rule declared in $rules. yii\web\GroupUrlRule
$ruleConfig array The default configuration of URL rules. yii\web\GroupUrlRule
$rules array The rules contained within this composite rule. yii\web\GroupUrlRule

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$createStatus integer|null Status of the URL creation after the last createUrl() call. yii\web\CompositeUrlRule

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__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
__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() {@inheritdoc} yii\web\GroupUrlRule
getCreateUrlStatus() Returns status of the URL creation after the last createUrl() call. yii\web\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() {@inheritdoc} yii\web\GroupUrlRule
parseRequest() {@inheritdoc} yii\web\GroupUrlRule

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
createRules() {@inheritdoc} yii\web\GroupUrlRule
iterateRules() Iterates through specified rules and calls createUrl() for each of them. yii\web\CompositeUrlRule

Property Details

$prefix public property

The prefix for the pattern part of every rule declared in $rules. The prefix and the pattern will be separated with a slash.

public string $prefix null
$routePrefix public property

The prefix for the route part of every rule declared in $rules. The prefix and the route will be separated with a slash. If this property is not set, it will take the value of $prefix.

public string $routePrefix null
$ruleConfig public property

The default configuration of URL rules. Individual rule configurations specified via $rules will take precedence when the same property of the rule is configured.

public array $ruleConfig = ['class' => 'yii\web\UrlRule']
$rules public property

The rules contained within this composite rule. Please refer to yii\web\UrlManager::$rules for the format of this property.

See also:

public array $rules = []

Method Details

createRules() protected method

{@inheritdoc}

protected void createRules ( )
createUrl() public method

{@inheritdoc}

public void createUrl ( $manager, $route, $params )
$manager
$route
$params
init() public method

{@inheritdoc}

public void init ( )
parseRequest() public method

{@inheritdoc}

public void parseRequest ( $manager, $request )
$manager
$request