We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Whether Acl surpport Module or not?

There are many modules in my project and i check the doc for acl,like this:

$allowed = $acl->isAllowed($role, $controller, $action);

but,i want to know,whether acl support make the pemission for each module

我想知道Acl是否还支持模块(module),我在看文档的时候,只提到了 isAllowed 中的三个参数,没有模块,请问如何在模块中也实现这样的权限呢?



7.9k
edited Sep '14

As far as I know it doesn't support module but this trick below maybe can help to self your problem:

$module = $dispatcher->getModuleName();
$action = $dispatcher->getActionName();
$controller = strtolower($module) . "." . $dispatcher->getControllerName();

$acl = $this->getAcl();

$allowed = $acl->isAllowed($role, $controller, $action);

You can concat module name and controller name

ACL is based on 'Resources', in which a Resource can technically be anything you desire, you're not limited to controllers only.

https://docs.phalcon.io/en/latest/api/Phalcon_Acl.html



10.3k
edited Sep '14

thanks all you two guys,your idea is good for me, i think I have found the best method to solve this problem, thank you very much again. Just like @Mitchell said "you are not limited to controllers only"



2.6k

I had a similar problem a few days back when I posted a question here in te ACL category. I think it is a little confusing to call the paramaters 'controller' and 'action'. Role makes sense, but the other 2 can technically be whatever you like. I personally thought (And I am a little new to PHP here) that, 'underneath the hood', Phalcon did some magic with the ACL's and that it required paramater 1 to match the name of a valid controlller and paramater 2 to match the name of a valid aciton within that controller.

An example that uses ACL without controllers + actions could be useful for the docs?