yii\base\Module::createController PHP Метод

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

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.
Результат array | boolean If the controller is created successfully, it will be returned together with the requested action ID. Otherwise `false` will be returned.
    public function createController($route)
    {
        if ($route === '') {
            $route = $this->defaultRoute;
        }
        // double slashes or leading/ending slashes may cause substr problem
        $route = trim($route, '/');
        if (strpos($route, '//') !== false) {
            return false;
        }
        if (strpos($route, '/') !== false) {
            list($id, $route) = explode('/', $route, 2);
        } else {
            $id = $route;
            $route = '';
        }
        // module and controller map take precedence
        if (isset($this->controllerMap[$id])) {
            $controller = Yii::createObject($this->controllerMap[$id], [$id, $this]);
            return [$controller, $route];
        }
        $module = $this->getModule($id);
        if ($module !== null) {
            return $module->createController($route);
        }
        if (($pos = strrpos($route, '/')) !== false) {
            $id .= '/' . substr($route, 0, $pos);
            $route = substr($route, $pos + 1);
        }
        $controller = $this->createControllerByID($id);
        if ($controller === null && $route !== '') {
            $controller = $this->createControllerByID($id . '/' . $route);
            $route = '';
        }
        return $controller === null ? false : [$controller, $route];
    }

Usage Example

Пример #1
0
 public function createController($route)
 {
     if ($this->beforeCreateController !== null && !call_user_func($this->beforeCreateController, $route)) {
         return false;
     }
     return parent::createController($route);
 }
All Usage Examples Of yii\base\Module::createController