Module Console- and Web-Controller

I want to write a Module for the YII2 Advanced Template. I would like to have two controllers with the same name,

one for console, one for web (backend). Calling the console controller works fine. Calling the controller in the backend uses the console controller instead of the web controller.

An idea would be to add a route in the Module.php, deciding either Console is requesting or not and redirecting to the responsible controller, but I don´t know how…? I know it would be simplier to use different names, but in case of the application logic, I would prefer identically names.

This is how the Module Directory Structure looks like:

  • vendor

– kfe

— yii2-my-module

---- console

----- RepositoryController.php (extends from yii\console\Controller)

---- controllers

----- RepositoryController.php (extends from yii\web\Controller)

---- migrations

---- models

---- views

---- Module.php

This is how the init function of Module.php is overridden:




    /**

     * @inherit doc

     */

    public function init()

    {

        parent::init();


        if (!isset($this->controllerMap['repository'])) {

            $this->controllerMap['repository'] = 'kfe\mymodule\console\RepositoryController';

        }


    }