If you've spent anytime wanting to use ACL on your applications, you know how tedious it can be to manually enter your entire controller and action structure. This Task will handle finding and loading or updating all of those for you whenever you run it from the command line.
This code is setup as a task so that it can be executed by any Cake shell that includes it. All that you need to do to run it in your application is create an empty shell:
/app/vendors/shells/task_runner.php
<?php class TaskRunnerShell extends Shell { var $tasks = array('AclControllers');
function main() { $this->print_instructions(); }
function print_instructions() { $this->out("\\nCommands"); $this->hr();
That's just a wrapper shell that I like to use that will run through all of it's included tasks, find the 'description' variable and list the command to execute with the description.
Next, you'll want to add the acl_controllers.php task to
/app/vendors/shells/tasks/acl_controllers.php
<?php class AclControllersTask extends Shell {
//Used when printing instructions var $description = 'Automatically loads controllers and actions into ACOs'; var $filter = array();
function startup() { App::import('Core','Controller'); App::import('Component','Acl');
The ONLY assumption that this code makes is that your ACO table has a node with an 'alias' of 'ROOT' that all of the controllers and actions will use as a parent. If you're using something other than root, the code looking for it is on line 57.
To run it, just run over to your cake/console directory and type
My name is Barry Jones and Brightball is my consulting company. We help business leaders understand the long term effects of their technical decisions as well as navigating the process of interviewing software developers.
I also blog about technical topics quite a bit. If you enjoy my writing and want to support the habit please use my referrals to help me pay for my servers with Digital Ocean, my DNS with DNS Made Easy and my email with Sendwithus.