phpcodeigniterhmvc

Setup Route Controller Only That Affect To Method


I have project that use pure CI. Now I want migrate to CI HMVC. Found problem in route.

For example, this is the directory

- config
-- routes.php
- applications
-- modules
--- moduleA
---- controllers
------ login.php
--- moduleB
---- controllers
------ anothercontroller.php

In login.php, I have 2 methods, index() and test(). In config > routes.php, I defined

 $route['login'] = 'moduleA/login';

Then, I open localhost/CI/login, page successfully opened. But, when I open localhost/CI/login/test, its return 404. I must define $route['login/test'] = 'moduleA/login/test' to open my test method. Is there another way that I just define controller only instead define method? I have >50 method and that's need more effort.

Thanks :)


Solution

  • As described in the CI Manual for routing it is possible to use wildcards or even regex or in your routing.

    This would be something applicable to your question:

    $route['login/(:any)'] = 'moduleA/login/$1';