yii\web\UrlManager::addRules PHP Метод

addRules() публичный Метод

This method will call UrlManager::buildRules to parse the given rule declarations and then append or insert them to the existing [[rules]]. Note that if [[enablePrettyUrl]] is false, this method will do nothing.
public addRules ( array $rules, boolean $append = true )
$rules array the new rules to be added. Each array element represents a single rule declaration. Please refer to [[rules]] for the acceptable rule format.
$append boolean whether to add the new rules by appending them to the end of the existing rules.
    public function addRules($rules, $append = true)
    {
        if (!$this->enablePrettyUrl) {
            return;
        }
        $rules = $this->buildRules($rules);
        if ($append) {
            $this->rules = array_merge($this->rules, $rules);
        } else {
            $this->rules = array_merge($rules, $this->rules);
        }
    }

Usage Example

Пример #1
0
 public function addRules($rules, $append = true)
 {
     foreach ($rules as $key => $rule) {
         if (isset($rule['composition'])) {
             foreach ($rule['composition'] as $composition => $pattern) {
                 $rules[] = ['pattern' => $pattern, 'route' => $composition . '/' . $rule['route']];
             }
         }
     }
     return parent::addRules($rules, $append);
 }