I update to v3.3.0 just before doing the ACL
Versions:
Phalcon DevTools Version: 3.2.5
Phalcon Version: 3.3.0
AdminLTE Version: 2.3.6
Here is where I use it (in a ControllerBase)
public function beforeExecuteRoute(Dispatcher $dispatcher)
{
$controllerName = $dispatcher->getControllerClass();
// Only check permissions on private controllers
if ($this->acl->isPrivate($controllerName)) {
// Get the current identity
$identity = $this->auth->getIdentity();
// If there is no identity available the user is redirected to index/index
if (!is_array($identity)) {
$this->flashSession->error('You don\'t have access to this module: private');
$dispatcher->setNamespaceName('App\Controllers');
$dispatcher->forward([
'controller' => 'index',
'action' => 'index'
]);
return false;
}
// Check if the user have permission to the current option
$actionName = $dispatcher->getActionName();
//hack to have "real" camelCase, starting by lowercase char
$actionName = lcfirst($actionName);
if (!$this->acl->isAllowed($identity['profile'], $controllerName, $actionName)) {
$this->flashSession->notice('You don\'t have access to this module: ' . $controllerName . ':' . $actionName);
if ($this->acl->isAllowed($identity['profile'], $controllerName, 'index')) {
$dispatcher->setNamespaceName($dispatcher->getNamespaceName());
$dispatcher->forward([
'controller' => $dispatcher->getControllerName(),
'action' => 'index'
]);
} else {
$response = $this->response;
$this->auth->remove();
//force the namespace
$dispatcher->setNamespaceName('App\Controllers');
$dispatcher->forward([
'controller' => 'index',
'action' => 'index'
]);
}
return false;
}
}
}
From vokuro ControllerBase, I changed the check on controllerName only to controllerClass, because I have multiple times the same controller name, but not in the same namespace/folder and the lcfirst to get real cameCase on the actionName (and the redirection too)
The actions definition in a privateResources config file are in "normal" camelCase, same for the permissions in db.
Just thought about this, but I use this routing rule to match my private resources
$router->add(
'/admin/:controller/([a-zA-Z0-9_-]*)/:params',
[
'namespace' => 'App\Controllers\Admin',
'controller' => 1,
'action' => 2,
'params' => 3,
]
)->convert('action', function($action) {
return Phalcon\Text::camelize($action);
});
Don't think it's related to the camelize function, though.