Welcome Guest, Not a member yet? Register   Sign In
Routing default controller feature?
#1

[eluser]Swedie[/eluser]
Hey, I've loaded a default controller named smc.
Now that I want a user to go to a method, it would have to be /smc/method and so on.
Can I somehow remove the need of including /smc and just have it be /method (from smc)?

Or would this cause too much of a conflict with core functions?
#2

[eluser]WanWizard[/eluser]
You can create a route so that you don't need to include the controller name in the URI.
But that is going to restrict you in using other controllers, unless you create routes for all those as well.

Alternatively you can extend the router library to add your custom features, or create a catch-all controller and do some custom stuff in there (check Modular CI's modulerouter controller for an example).
#3

[eluser]Swedie[/eluser]
Thanks. That worked.

Can I from inside a Controller (or sub class that extends the controller) change or specificy such rules without having to go add it manually to the config/routes.php file?
#4

[eluser]WanWizard[/eluser]
No, routes are processed long before the controller is instantiated.

This is why Modular CI has the modulerouter. A normal controller, that can make custom routing decisions and has full CI access, and uses Modular CI to load the destination controller (which may be a module or in the application folder).

Alternatively you can extend the router library, but also there your access to CI is limited (for example no database access).




Theme © iAndrew 2016 - Forum software by © MyBB