André Luiz André Luiz - 1 year ago 199
PHP Question

Phalcon PhP - how to use $this->acl->isAllowed in .volt view

I'm working in a Phalcon 2.0.13 Project using the ACL to control permissions. My Question is: is there a way for me to use the isAllowed in a .volt view?

My goal is to control some options I show in the .volt view based on user's permissions.

Just to clarify to which function I mean:

if( !$this->acl->isAllowed( $userRole, ucfirst( $this->dispatcher->getControllerName() ), $this->dispatcher->getActionName() ) ){
$this->response->redirect( $this->url->get(['for' => 'admin-index-login']) );


This is a piece of code I run inside my base controller, I would like to check for permissions in the .volt view, something like
{{ if isAllowed("User", "New") }} xxxx {{ endif }}

Thanks for any help

Answer Source

If acl is added as service then just do:

{% if acl.isAllowed("User", "New") %}

{% endif %}

No need to custom function in volt. Phalcon ACL Memory based have a lot more options than database and it's faster anyway.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download