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

Initializes UrlManager.
public init ( )
Пример #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();
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $languages = Yii::$app->appLanguage->getAppLanguages();
     $joinLanguages = implode('|', $languages);
     $this->rules = ['/' => '/' . Yii::$app->language, '<language:' . $joinLanguages . '>/<module:[\\w\\-]+>/<controller:[\\w\\-]+>/<action:[\\w\\-]+>' => '<module>/<controller>/<action>', '<language:' . $joinLanguages . '>/<controller:[\\w\\-]+>/<action:[\\w\\-]+>/<id:\\d+>' => '<controller>/<action>', '<language:' . $joinLanguages . '>/<controller:[\\w\\-]+>/<action:[\\w\\-]+>' => '<controller>/<action>', '<language:' . $joinLanguages . '>/<controller>' => '<controller>'];
     parent::init();
 }
Пример #3
0
 /**
  * Initializes UrlManager.
  */
 public function init()
 {
     parent::init();
     if (Yii::$app->request->getIsConsoleRequest()) {
         return true;
     }
     //set $this->langBegin is empty
     $this->setLangBegin();
     $request = Yii::$app->getRequest();
     $sourcePathInfo = $request->getPathInfo();
     $endSlash = '';
     if ($this->normalizer !== false) {
         $pathInfo = $this->normalizer->normalizePathInfo($sourcePathInfo, (string) $this->suffix, $this->normalized);
         if ($sourcePathInfo !== $pathInfo) {
             $endSlash = '/';
         }
     } else {
         $pathInfo = rtrim($sourcePathInfo, '/');
     }
     $suffix = (string) $this->suffix;
     if ($suffix !== '' && $pathInfo !== '') {
         $n = strlen($this->suffix);
         if (substr_compare($pathInfo, $this->suffix, -$n, $n) === 0) {
             $pathInfo = substr($pathInfo, 0, -$n);
             if ($pathInfo === '') {
                 // suffix alone is not allowed
                 throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
             }
         } else {
             // suffix doesn't match
             throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
         }
     }
     if ($this->enableLang) {
         if ($pathInfo != '') {
             if (strpos($pathInfo, '/') !== false) {
                 $segments = explode('/', $pathInfo);
                 $_GET[$this->langParam] = $segments['0'];
                 unset($segments['0']);
                 $pathInfo = join('/', $segments);
             } else {
                 if (in_array($pathInfo, $this->langBegin)) {
                     $_GET[$this->langParam] = $pathInfo;
                     $pathInfo = '';
                 }
             }
         } else {
             $_GET[$this->langParam] = reset($this->langBegin);
         }
     }
     $event = new UrlManagerEvent(['pathInfo' => $pathInfo]);
     $this->trigger(self::EVENT_INIT, $event);
     if (isset($_GET)) {
         foreach ($_GET as $k => $v) {
             $this->gets[$k] = $v;
         }
     }
     $request->setPathInfo($event->pathInfo . $endSlash);
     $this->_pathInfo = $event->pathInfo;
 }
Пример #4
0
 public function init()
 {
     parent::init();
     $event = new UrlRuleCacheEvent(["ruleCache" => $this->_ruleCache, "urlManager" => $this]);
     $this->trigger(static::EVENT_INIT_RULECACHE, $event);
     $this->_ruleCache = $event->ruleCache;
 }
Пример #5
0
 /**
  * Initializes UrlManager.
  */
 public function init()
 {
     parent::init();
     if (empty($this->language)) {
         $this->language = Yii::$app->language;
     }
 }
Пример #6
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (is_callable($this->languages)) {
         $this->languages = call_user_func($this->languages);
     }
     if (empty($this->languages)) {
         $this->languages = [Yii::$app->language];
     }
     parent::init();
 }
Пример #7
0
 public function init()
 {
     parent::init();
     $this->defaultLanguage = \Yii::$app->sourceLanguage;
     $this->conteiner = new Container();
     if (!isset($this->languageProvider)) {
         throw new InvalidConfigException('$languageProvider must be set');
     }
     $this->registerDependencies();
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     $this->languages = Language::find()->asArray()->select('lang_id')->where(['active' => true])->all();
     $this->languages = ArrayHelper::getColumn($this->languages, 'lang_id');
     if ($this->languages) {
         if (!$this->enablePrettyUrl) {
             throw new InvalidConfigException('Locale URL support requires enablePrettyUrl to be set to true.');
         }
     }
     $this->_defaultLanguage = Yii::$app->language;
     parent::init();
 }
 /**
  * init
  *
  * Adding language prefixes to url rules
  */
 public function init()
 {
     $languages = array_keys(Yii::$app->params['mlConfig']['languages']);
     if (count($languages) > 0) {
         $langPrefix = '<_language:(' . implode('|', $languages) . ')>/';
         $finalRules[$langPrefix] = '/';
         foreach ($this->rules as $rule => $path) {
             if (is_array($path) && isset($path['pattern']) && isset($path[0])) {
                 $finalRules[$langPrefix . ltrim($path['pattern'], '/')] = $path[0];
             } else {
                 $finalRules[$langPrefix . ltrim($rule, '/')] = $path;
             }
         }
         $this->rules = $finalRules;
     }
     parent::init();
 }
Пример #10
0
 /** @inheritdoc */
 public function init()
 {
     parent::init();
 }
Пример #11
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->enableLocaleUrls && $this->languages) {
         if (!$this->enablePrettyUrl) {
             throw new InvalidConfigException('Locale URL support requires enablePrettyUrl to be set to true.');
         }
     }
     $this->_defaultLanguage = Yii::$app->language;
     return parent::init();
 }
Пример #12
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->enableLocaleUrls && $this->languages) {
         if (!$this->enablePrettyUrl) {
             throw new InvalidConfigException('Locale URL support requires enablePrettyUrl to be set to true.');
         }
         if (empty($this->languages)) {
             throw new \yii\base\InvalidConfigException('Missing languages');
         } else {
             if (is_callable($this->languages)) {
                 $this->languages = call_user_func($this->languages);
             }
         }
     }
     $this->_defaultLanguage = Yii::$app->language;
     return parent::init();
 }
Пример #13
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->languages == null) {
         if (Module::hasMultiLanguage()) {
             $languages = \navatech\language\helpers\MultiLanguageHelper::getLanguages();
             foreach ($languages as $language) {
                 $this->languages[] = $language['code'];
             }
         } else {
             throw new InvalidConfigException('If "navatech/yii2-multi-language" does not exists, please special "language" in config file.');
         }
     }
     if ($this->enableLocaleUrls && $this->languages) {
         if (!$this->enablePrettyUrl) {
             throw new InvalidConfigException('Locale URL support requires enablePrettyUrl to be set to true.');
         }
     }
     $this->_defaultLanguage = Yii::$app->language;
     return parent::init();
 }
Пример #14
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     //attach handler to save memory data
     Yii::$app->on(Application::EVENT_BEFORE_ACTION, function ($event) {
         if ($this->isMemoryRelevant()) {
             $this->saveRememberedParams();
         }
     });
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->enablePrettyUrl) {
         throw new InvalidConfigException('UrlManager::enablePrettyUrl need to be true for using language url manager.');
     }
     $this->fillLanguages();
     if (!is_array($this->languages)) {
         throw new InvalidConfigException('UrlManager::languages have to be array.');
     }
     if (empty($this->languages)) {
         throw new InvalidConfigException('UrlManager::languages have to contains at least 1 item.');
     }
     $this->normalizeLanguages();
     if (!isset($this->languages[$this->defaultLanguage])) {
         throw new InvalidConfigException('UrlManager::defaultLanguage have to be exist in UrlManager::languages.');
     }
     $this->languageRules = $this->rules;
     if (empty($this->languageRules)) {
         throw new InvalidConfigException('UrlManager::rules required to be specified.');
     }
     parent::init();
     if ($this->autoLanguageRules) {
         $this->setUpLanguageUrls();
     }
 }
Пример #16
0
 public function init()
 {
     $this->languages = Language::getAllLang();
     parent::init();
 }
Пример #17
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $languages = Lang::find()->all();
     foreach ($languages as $language) {
         $this->languages[] = $language->getAttribute('url');
     }
     if ($this->enableLocaleUrls && $this->languages) {
         if (!$this->enablePrettyUrl) {
             throw new InvalidConfigException('Locale URL support requires enablePrettyUrl to be set to true.');
         }
     }
     $this->_defaultLanguage = Lang::getDefaultLang()->getAttribute('url');
     return parent::init();
 }
Пример #18
0
 public function init()
 {
     $this->assignRule();
     $this->rules = BaseArrayHelper::merge($this->mainRules, $this->rules);
     return parent::init();
 }