Welcome Guest, Not a member yet? Register   Sign In
A list of the available controllers
#1

[eluser]Unknown[/eluser]
Hi,
Im currently doing my first steps with CodeIgniter & MVC (and liking it :-) ).
I wondered if there is a way to get a list of the available controllers in my application, dynamically of course, so i can use it to present some kind of a menu.
#2

[eluser]xwero[/eluser]
It's very tempting to do this but a url doesn't always have a direct link with the controller. For example if you add routes the controller url segment can be a but it can route to controller z or method a from controller f. Or if you want to make a controller more SEO friendly by using dashes instead of underscores.

So to make your code as flexible as possible it's best you find another way to generate your menu links.
#3

[eluser]GSV Sleeper Service[/eluser]
you could just read the application/controllers folder and list the files. quick and dirty.
#4

[eluser]Unknown[/eluser]
i guess ill go with the files approach.
i was wondering if there is a built-in way to do it.

thanks for your inputs
#5

[eluser]xwero[/eluser]
There is no build-in way because CI only checks the controller that is called by the url based on files. CI doesn't keep a registry of all the known controllers.

A way to mimic a registry is to add all possible urls to the routes.php file and extract them form there. But then you can't use too much regex magic or you need to write a regex aware parser.




Theme © iAndrew 2016 - Forum software by © MyBB