createController() public method

The route should be relative to this module. The method implements the following algorithm to resolve the given route: 1. If the route is empty, use [[defaultRoute]]; 2. If the first segment of the route is a valid module ID as declared in [[modules]], call the module's createController() with the rest part of the route; 3. If the first segment of the route is found in [[controllerMap]], create a controller based on the corresponding configuration found in [[controllerMap]]; 4. The given route is in the format of abc/def/xyz. Try either abc\DefController or abc\def\XyzController class within the [[controllerNamespace|controller namespace]]. If any of the above steps resolves into a controller, it is returned together with the rest part of the route which will be treated as the action ID. Otherwise, false will be returned.
public createController ( string $route ) : array | boolean
$route string the route consisting of module, controller and action IDs.
return array | boolean If the controller is created successfully, it will be returned together with the requested action ID. Otherwise `false` will be returned.
Example #1
0
 public function createController($route)
 {
     if ($this->beforeCreateController !== null && !call_user_func($this->beforeCreateController, $route)) {
         return false;
     }
     return parent::createController($route);
 }
Example #2
0
 /**
  * Override createController()
  * @link https://github.com/yiisoft/yii2/issues/810
  * @link http://www.yiiframework.com/forum/index.php/topic/21884-module-and-url-management/
  *
  * @param string $route
  *
  * @return array|bool
  */
 public function createController($route)
 {
     preg_match('/(default)/', $route, $match);
     if (isset($match[0])) {
         return parent::createController($route);
     }
     return parent::createController("{$this->defaultRoute}/{$route}");
 }
Example #3
0
 public function createController($route)
 {
     if (strpos($route, 'admin/') !== false) {
         return $this->getModule('admin')->createController(str_replace('admin/', '', $route));
     } else {
         return parent::createController($route);
     }
 }
Example #4
0
 /**
  * Override createController()
  *
  * @link https://github.com/yiisoft/yii2/issues/810
  * @link http://www.yiiframework.com/forum/index.php/topic/21884-module-and-url-management/
  */
 public function createController($route)
 {
     preg_match('/(default)/', $route, $match);
     if (isset($match[0])) {
         return parent::createController($route);
     }
     $this->defaultRoute = !$this->defaultRoute || $this->defaultRoute == 'default' ? 'url' : $this->defaultRoute;
     if (sizeof(explode('/', $route)) > 1) {
         list($this->defaultRoute, $route) = explode('/', $route);
     }
     return parent::createController("{$this->defaultRoute}/{$route}");
 }
Example #5
0
 public function createController($route)
 {
     // check valid routes
     $validRoutes = [$this->defaultRoute, "admin", "album", "json"];
     $isValidRoute = false;
     foreach ($validRoutes as $validRoute) {
         if (strpos($route, $validRoute) === 0) {
             $isValidRoute = true;
             break;
         }
     }
     return (empty($route) or $isValidRoute) ? parent::createController($route) : parent::createController("{$this->defaultRoute}/{$route}");
 }
Example #6
0
 public function createController($route)
 {
     $this->normalizeController();
     return parent::createController($route);
 }
Example #7
0
 /**
  * Modify createController() to handle routes in the default controller
  *
  * This is a temporary hack until they add in url management via modules
  * @link https://github.com/yiisoft/yii2/issues/810
  * @link http://www.yiiframework.com/forum/index.php/topic/21884-module-and-url-management/
  *
  * "usr" and "usr/default" work like normal
  * "usr/xxx" gets changed to "usr/default/xxx"
  *
  * @inheritdoc
  */
 public function createController($route)
 {
     if (\Yii::$app instanceof \yii\console\Application) {
         return parent::createController($route);
     }
     // check valid routes
     $validRoutes = [$this->defaultRoute, 'auth', 'manager'];
     $isValidRoute = false;
     foreach ($validRoutes as $validRoute) {
         if (strpos($route, $validRoute) === 0) {
             $isValidRoute = true;
             break;
         }
     }
     if (!empty($route) && !$isValidRoute) {
         $route = $this->defaultRoute . '/' . $route;
     }
     return parent::createController($route);
 }
Example #8
0
 public function createController($route)
 {
     return parent::createController($this->realRoute ? $this->realRoute : $route);
 }
Example #9
0
 public function createController($route)
 {
     return $this->beforeCreateController($route) ? parent::createController($route) : false;
 }
Example #10
0
 /**
  * Modify createController() to handle routes in the default controller
  *
  * This is a temporary hack until they add in url management via modules
  *
  * @link https://github.com/yiisoft/yii2/issues/810
  * @link http://www.yiiframework.com/forum/index.php/topic/21884-module-and-url-management/
  *
  * "user", "user/default", "user/admin", and "user/copy" work like normal
  * any other "user/xxx" gets changed to "user/default/xxx"
  *
  * @inheritdoc
  */
 public function createController($route)
 {
     // check valid routes
     $validRoutes = [$this->defaultRoute, "admin", "copy", "auth", "abonnement", 'company', "user-activities"];
     $isValidRoute = false;
     foreach ($validRoutes as $validRoute) {
         if (strpos($route, $validRoute) === 0) {
             $isValidRoute = true;
             break;
         }
     }
     return (empty($route) or $isValidRoute) ? parent::createController($route) : parent::createController("{$this->defaultRoute}/{$route}");
 }