yii\web\UrlManager::init PHP Method

init() public method

Initializes UrlManager.
public init ( )
    public function init()
    {
        parent::init();
        if ($this->normalizer !== false) {
            $this->normalizer = Yii::createObject($this->normalizer);
            if (!$this->normalizer instanceof UrlNormalizer) {
                throw new InvalidConfigException('`' . get_class($this) . '::normalizer` should be an instance of `' . UrlNormalizer::className() . '` or its DI compatible configuration.');
            }
        }
        if (!$this->enablePrettyUrl || empty($this->rules)) {
            return;
        }
        if (is_string($this->cache)) {
            $this->cache = Yii::$app->get($this->cache, false);
        }
        if ($this->cache instanceof Cache) {
            $cacheKey = $this->cacheKey;
            $hash = md5(json_encode($this->rules));
            if (($data = $this->cache->get($cacheKey)) !== false && isset($data[1]) && $data[1] === $hash) {
                $this->rules = $data[0];
            } else {
                $this->rules = $this->buildRules($this->rules);
                $this->cache->set($cacheKey, [$this->rules, $hash]);
            }
        } else {
            $this->rules = $this->buildRules($this->rules);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->enablePrettyUrl) {
         throw new InvalidConfigException('Locale URL support requires enablePrettyUrl to be set to true.');
     }
     return parent::init();
 }
All Usage Examples Of yii\web\UrlManager::init