src/base/Module.php
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) {
            [$id, $route] = explode('/', $route, 2);
        } else {
            $id = $route;
            $route = '';
        }

        // module and controller map take precedence
        if (isset($this->controllerMap[$id])) {
            $controller = $this->app->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];
    }
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) {
            [$id, $route] = explode('/', $route, 2);
        } else {
            $id = $route;
            $route = '';
        }

        // module and controller map take precedence
        if (isset($this->controllerMap[$id])) {
            $controller = $this->app->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];
    }
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 ) { [ $ id , $ route ] = explode ( '/' , $ route , 2 ) ; } else { $ id = $ route ; $ route = '' ; } // module and controller map take precedence if ( isset ( $ this -> controllerMap [ $ id ] ) ) { $ controller = $ this -> app -> 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 ] ; }
Creates a controller instance based on the given route.

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.

@param string $route the route consisting of module, controller and action IDs.
@return array|bool If the controller is created successfully, it will be returned together
with the requested action ID. Otherwise `false` will be returned.
@throws InvalidConfigException if the controller class and its file do not match.
Creates a controller instance based on the given route .