ZF 1.0

Simple example

The very simplest way you can use Zend_Acl is building the ACL in code

$frontController->registerPlugin(new Application_Plugin_Acl(new Zend_Acl()));

require_once "Zend/Controller/Plugin/Abstract.php";

class Application_Plugin_Acl extends Zend_Controller_Plugin_Abstract {
	private $_acl = null;

	public function __construct(Zend_Acl $acl) {
		// roles
		$this->_acl->addRole(new Zend_Acl_Role('guest'));
		$this->_acl->addRole(new Zend_Acl_Role('user'), 'guest'); // Add a role called user, which inherits from guest

		// resource
		$this->_acl->add(new Zend_Acl_Resource('index'));
		$this->_acl->add(new Zend_Acl_Resource('restricted'), 'index'); // Add a resource called restricted, which inherits index

		// privileges
		$this->_acl->allow('guest', 'index', 'view'); // Allow guests to view frontend
		$this->_acl->allow('user', 'restricted', 'comment'); // Users can comment news

	public function preDispatch(Zend_Controller_Request_Abstract $request) {

		$role = Zend_Auth::getInstance()->hasIdentity() ? 'user' : 'guest';

		if ( ! $this->_acl->isAllowed($role, 'restricted', 'comment')) {