slash in the string.
I wrote a little function (get_aco_node) because I was having a
similar problem with the code in the cookbook.
I added the following action and function to my users_controller to do
my initial Aco setup:
/**
* Rebuild the Acl based on the current controllers in the
application
*
* @return void
*/
function buildAcl() {
$log = array();
$aco =& $this->Acl->Aco;
$root = $this->_get_aco_node('controllers');
$this->Acl->Allow('Admin','controllers','*');
$log[] = 'Allowed access to controllers for admin user';
App::import('Core', 'File');
$Controllers = Configure::listObjects('controller');
foreach($Controllers as $ctrlName){
if (!App::import('Controller', $ctrlName))
{
$log[] = 'Import of '.$ctrlName.' failed';
} else {
$log[] = 'Import of '.$ctrlName.' succeeded';
}
}
$Plugins = $this->_get_plugin_controller_names();
$Controllers = array_merge($Controllers, $Plugins);
$appIndex = array_search('App', $Controllers);
if ($appIndex !== false ) {
unset($Controllers[$appIndex]);
}
$baseMethods = get_class_methods('Controller');
// $baseMethods[] = 'buildAcl';
// look at each controller in app/controllers
foreach ($Controllers as $ctrlName) {
$isPlugin = false;
$ctrlclass = $ctrlName . 'Controller';
$methods = get_class_methods($ctrlclass);
// find / make controller node
$controllerNode = $this->_get_aco_node('controllers/'.
$ctrlName,$root['Aco']['id']);
$log[] = 'Found/made node for controllers/'.$ctrlName;
if ($methods != null){
// Now create the methods ...
foreach ($methods as $k => $method) {
if (strpos($method, '_', 0) === 0) {
unset($methods[$k]);
continue;
}
if (in_array($method, $baseMethods)) {
unset($methods[$k]);
continue;
}
$methodNode = $this->_get_aco_node('controllers/'.
$ctrlName.'/'.$method, $controllerNode['Aco']['id']);
$log[] = 'Found/made node for controllers/'.
$ctrlName.'/'.$method;
}
} else {
$log[] = 'No methods for '.$ctrlName;
}
}
$user_controller_node = $this->_get_aco_node('controllers/
User', $controllerNode['Aco']['id']);
$user_login_node = $this->_get_aco_node('controllers/User/
login', $user_controller_node['Aco']['id']);
$this->Acl->Allow('User',
'controllers/User/login',
'*'
);
$user_logout_node = $this->_get_aco_node('controllers/User/
logout', $user_controller_node['Aco']['id']);
$this->Acl->Allow('User',
'controllers/User/logout',
'*'
);
$init_acl_controller_node = $this->_get_aco_node('controllers/
InitAcl', $controllerNode['Aco']['id']);
$init_acl_build_acl_node = $this->_get_aco_node('controllers/
InitAcl/buildAcl', $user_controller_node['Aco']['id']);
debug($log);
}
function _get_aco_node($new_node = null, $parent_id = null){
$aco =& $this->Acl->Aco;
$aco_node = $aco->node($new_node);
if (!$aco_node) {
$path = explode('/',$new_node);
$ctrlName = array_pop($path);
$aco->create(array('parent_id' => $parent_id, 'model' =>
null, 'alias' => $ctrlName));
$aco_node = $aco->save();
$aco_node['Aco']['id'] = $aco->id;
$log[] = 'Created new node for '.$new_node;
} else {
$log[] = 'Aco node for '.$new_node.' already exists';
$aco_node = $aco_node[0];
}
$this->Acl->Allow('Admin',
$new_node,
'*'
);
return $aco_node;
}
Then my logic to set up the
On Dec 2, 2:42 am, "Liebermann, Anja Carolin"
<anja.lieberm...@alltours.de> wrote:
>
> $this->Acl->allow($gruppe,
> 'controllers/Bilds/','create'); //This is line 129 which throws the
> error
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment