I am wondering whats the way to use Zend_Acl to show/hide parts of view? I am thinking I will
Create a Controller Plugin that passes the logged in user + acl to view
$this->view->loggedInUser = Zend_Auth::getIdentity();
$this->view->acl = Zend_Registry::get('acl');
Then in view scripts do something like
$this->acl->isAllowed($this->view->loggedInUser, 'resource', 'privilege');
Or is there a better way? Or should I use a View Helper? That returns a boolean whether the logged in user is allowed?
You are using it in the view, so for me ViewHelper is correct place for that - I've done it once that way:
class Zend_View_Helper_HasAccess extends Zend_View_Helper_Abstract
{
private $_acl;
public function hasAccess($role, $controller, $action)
{
if (!$this->_acl) {
$this->_acl = Zend_Controller_Front::getInstance()->getPlugin('Acl');
//In yout case registry, but front controller plugin is better way to implement ACL
}
return $this->_acl->isAllowed($role, $controller, $action);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With