CodeIgniter Forums
Routing an entire controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Routing an entire controller (/showthread.php?tid=68648)



Routing an entire controller - desbest - 08-08-2017

I would like a new feature to be added so I can route an ENTIRE controller all at once, so I can route a controller to be / (root directory)?

Let's say my controller looks like this.

Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Main extends MY_Controller {

    public function debate($nodeviewid){

    }

    public function question($nodeviewid){

    }
}


By doing this (setting a route for my controller), all actions in my specific controller I set the controller's route in, (such as "debate") inherit this route so action debate has the /debate url and action question has the /question url.

It would be more convenient to map or route an entire controller and all actions in that controller by default become a subroute of it, than setting each route for each of my controller actions individually.


RE: Routing an entire controller - sv3tli0 - 08-08-2017

https://bcit-ci.github.io/CodeIgniter4/general/routing.html?highlight=route#examples

First example...


RE: Routing an entire controller - kilishan - 08-08-2017

Not likely to happen because it would require scanning php classes to determine which the routes to assign, and that could become a significant performance hit quickly.

However, if you only have one controller you want to do this to, you should be to set the 404Override to point to your controller, and check if the method exists or not in the controller.