What to do if your controller and module have the same name?

I’ve just been added to a huge project at my company that’s using Yii2. This project has a controller called UserController, which is used throughout the project. I’ve added a module, which I need to accomplish some of the tasks I’ve been assigned. Unfortunately, the module is named ‘user’. So after I added the module, the app can no longer access the actions in the UserController. For example, if I try to navigate to ‘/user/index’ it will look in the ‘user’ moudle for a controller called ‘index’, rather than looking for an action in the UserController for an action called ‘index’.

I know that I could change the name of the UserController, then go through the entire project and find everywhere that it’s used and change it, but that could take days. Is there any other way out of this situation? Is there some way to redirect to the controller if the route is not found in the module? Any help at all would be greatly appreciated.

Add a url rule in your main config for the module or the users controller so they aren’t the same url.

‘user’=>’user/user/index’, //‘DesiredUrl’=>’module/controller/action’

Thank you very much!

Glad it worked. Just be careful not to add a lot of url rules (group as many as possible) as it can effect performance.