没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Class yii\web\GroupUrlRule

继承yii\web\GroupUrlRule » yii\web\CompositeUrlRule » yii\base\BaseObject
实现yii\base\Configurable, yii\web\UrlRuleInterface
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/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.

公共属性

隐藏继承的属性

属性类型描述被定义在
$createUrlStatus null|integer Status of the URL creation after the last createUrl() call. yii\web\CompositeUrlRule
$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

受保护的属性

隐藏继承的属性

属性类型描述被定义在
$createStatus integer|null Status of the URL creation after the last createUrl() call. yii\web\CompositeUrlRule

公共方法

隐藏继承的方法

方法描述被定义在
__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() Creates a URL according to the given route and parameters. 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() Initializes the object. yii\web\GroupUrlRule
parseRequest() Parses the given request and returns the corresponding route and parameters. yii\web\GroupUrlRule

受保护的方法

隐藏继承的方法

方法描述被定义在
createRules() Creates the URL rules that should be contained within this composite rule. yii\web\GroupUrlRule
iterateRules() Iterates through specified rules and calls createUrl() for each of them. yii\web\CompositeUrlRule

属性详情

$prefix 公共 属性

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 公共 属性

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 公共 属性

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 公共 属性

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

参见:

public array $rules = []

方法详情

createRules() 受保护 方法

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

protected yii\web\UrlRuleInterface[] createRules()
return yii\web\UrlRuleInterface[]

The URL rules

createUrl() 公共 方法

Creates a URL according to the given route and parameters.

public string|boolean createUrl($manager, $route, $params)
$manager yii\web\UrlManager

The URL manager

$route string

The route. It should not have slashes at the beginning or the end.

$params array

The parameters

return string|boolean

The created URL, or false if this rule cannot be used for creating this URL.

init() 公共 方法

Initializes the object.

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

public void init()
parseRequest() 公共 方法

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

public array|boolean parseRequest($manager, $request)
$manager yii\web\UrlManager

The URL manager

$request yii\web\Request

The request component

return 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.