1
votes

How to organize controllers under /app/controllers in sub- folders in CakePHP? I want to create a folder like admin inside the controllers folder and I want to create some controller related to admin. If it is possible, then how can i call a controller from a sub folder?

3
Should your admin actions not belong to the main controllers for your app? You can use Routing Prefixes (set in app/Config/core.php) to add an "admin" prefix to the routes which also helps ensure the admin actions are easily identifiable in your controller. - drmonkeyninja

3 Answers

2
votes

You can use App::build() to let CakePHP know for additional packages/configurations.

App::build(array(
    'Controller' => array('/path/to/controllers', '/next/path/to/controllers')
));
1
votes

You need to re-think your application structure. Cake has something built in called prefix routing that you should probably be using.

This is also available in 1.x

-1
votes

You can't alter the CakePHP file structure "just like that". It would require serious modification of the core to achieve this, but there is almost never a good reason to do so. If you properly follow the naming conventions, everything should be easy to locate.

What you could do (that is still following conventions and comes close to what you're looking for) is create a plugin for all your admin related tasks and then you can put all that logic under app/Plugin/plugin_name/Controller instead. That way it has it's own place, although you will need to load the plugin from you main application for this to work.