Quicktips: Finding all the controllers in your cakePHP application
Published: on 25/6/08 | Comments (0)
Hi Everyone,
Quick tip for all cakePHP developers today, have you ever wanted to obtain a list within your code, of all the controllers in your application?
CakePHP makes this pretty simple with the $configure class, just use:
$controllerList = Configure::listObjects('controller');
and by the magic of cake $controllerList will now contain an array of controllers you can iterate through.
Within my own code, I tend to use it quite frequently to build a basic admin menu, by iterating through it in app_controller::beforeRender, and checking whether the currently authenticated user has permission to access the index action of each controller in the list, I can pass over an array to the view that if not empty can be used to create an element containing links to all the controllers that the current user has admin access to.
Anyway, hope some of you find this helpful, and...
