0

Well in ZF1 there was the isAllowed view helper to check the ACL in the view.

But I can't find an equivalent of it for ZF2. The closest I got was the ZF2 navigation view helper, but the problem with that is that it requires a AbstractPage. I just want to throw a resource/privilege to it, example:

$this->allowed('resource', 'privilege');

Is there not such a view helper, or am I looking at this all the wrong way?

MKroeders
  • 7,562
  • 4
  • 24
  • 39

1 Answers1

0

Well I couldn't find any view helper, neither got any response so I wrote my own view helper.

isAllowed view helper code

MKroeders
  • 7,562
  • 4
  • 24
  • 39
  • You can better make the ACL an argument for you constructor and create a factory for the view helper. This ensures you have the ACL injected before you use it, and you don't need to set it in the view itself. The same might be for the role, which you can inject based on the ZfcUser identity for example. – Jurian Sluiman Mar 23 '14 at 15:53
  • I looked at the ZF2 navigation and "copied" the idea. So I will look into it beter – MKroeders Mar 23 '14 at 16:43
  • The ACL view helper is injected into the layout. To access it in the view you need to call `$this->layout()->acl->isAllowed($role, $resource, $permission)` - http://stackoverflow.com/a/40219614/351785 – Richard Parnaby-King Oct 24 '16 at 13:28