tags:

views:

56

answers:

2

I'm building a CakePHP site for a client and I've got a bit of an interesting problem. They want to add a new feature whereby users can create their own landing pages within the site using this type of URL: http://mainsite.com/username. Since this is a Cake site, there are plenty of values for username that would result in all sorts of routing craziness, especially if they happened to pick a username that was the same as a controller within the site.

My approach is something like this: in the beforeValidate function of the Users controller, check the supplied username against a list of all of the controller names and return false if there's a match. My question is - how can I get a list of all of the controller names (short of actually looping over the files in /app/controllers)? Is it even possible to do this?

Thanks!

+2  A: 

You could probably use

$Controllers = Configure::listObjects('controller')
dr Hannibal Lecter
A: 

Perfect! The beginnings of my solution:

$human_controllers = Configure::listObjects('controller');
$u_controllers = array();
foreach($human_controllers as $c){
    $u_controllers[] = Inflector::underscore($c); // converts "PageContents" to "page_contents"
}
debug($u_controllers); die();
inkedmn