Zend_Acl

set_include_path('./library');
require_once('Zend_Loader');
Zend_Loader::loadClass('Zend_Acl');
Zend_Loader::loadClass('Zend_Acl_Role');
Zend_Loader::loadClass('Zend_Acl_Resource');
Zend_Loader::loadClass('Zend_Acl_Assert_Interface');
$acl->addRole(new Zend_Acl_Role('guest'));
$acl->addRole(new Zend_Acl_Role('staff'));
$acl->addRole(new Zend_Acl_Role('admin'));
$acl->addRole(new Zend_Acl_Role('someuser'),array('guest','staff','admin'));
$acl->add(new Zend_Acl_Resource('news'));
$acl->add(new Zend_Acl_Resource('latest'));
$acl->allow('guest','news','view');
$acl->deny('staff','news','edit');
echo $acl->isAllowed('guest','news','view'); //返回true
class CleanIPAssertion implements Zend_Acl_Assert_Interface {
public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
{ return $this->_isCleanIP($_SERVER['REMOTE_ADDR']); }
protected function _isCleanIP($ip)
{
if($ip=='127.0.0.1')
{ return false; }
return true;
}
}
$acl->allow('guest','news','view',new CleanIPAssertion()); $acl->isAllowed('guest','news','view');//这样如果是本地ip则返回false

你可能感兴趣的:(Zend_Acl)