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...

Happy baking!


Comments

Have Your Say

Comments are now closed for this article


About Studio Canaria

Studio Canaria is the web site of freelance web developer, Peter Butler. Articles on this site relate to designing, developing and marketing modern web applications.

Recent Comments

Dave on CakePHP Auth Component - Users, Groups & Permissions Revisited
I dont understand how you define permissions for each contoller to User. Do I have to manually...
SI on CakePHP Auth Component - Users, Groups & Permissions Revisited
Hi Peter,

I am having little issue logging into the application. I have 2 user groups both having...
Alig on CakePHP Auth Component - Users, Groups & Permissions Revisited
Thank you very much for this tutorial. After fighting for hours to get the cakephp ACL working,...
Benny on CakePHP Auth Component - Users, Groups & Permissions Revisited
thank you for your solution it's perfect , you are genius , thank you this is the best ( beside...
Gordon on CakePHP Auth Component - Users, Groups & Permissions Revisited
I'm having a similar problem to luis. I followed everything as instructed here up to the point...