<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NeatCN(NeatStudio工作室) &#187; acl</title>
	<atom:link href="http://www.neatcn.com/tags/acl/feed" rel="self" type="application/rss+xml" />
	<link>http://www.neatcn.com</link>
	<description>NeatStudio工作室</description>
	<lastBuildDate>Fri, 09 Dec 2011 13:07:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>简单学习一下Zend_ACL</title>
		<link>http://www.neatcn.com/show-35-1.shtml</link>
		<comments>http://www.neatcn.com/show-35-1.shtml#comments</comments>
		<pubDate>Wed, 24 Mar 2010 07:32:14 +0000</pubDate>
		<dc:creator>膘叔</dc:creator>
				<category><![CDATA[PHP开发]]></category>
		<category><![CDATA[acl]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.neatcn.com/?p=35</guid>
		<description><![CDATA[如果不想用rbac那么，简单权限管理ACL，应该是最方便的了。简要说一下原理吧。。 这个文件是放在/application/models/目录下的Acl.php，调用的时候就直接 $identity = Zend_Auth::getInstance()->getIdentity(); $acl = new Application_Model_Acl(); //然后判断 if( $acl->isAllowed( $identity['Role'] , 'xxxxx' ,'yyyy' )); //xxxx是controller名，yyyy是controller里的action名称。不用额外加action。。。 class Application_Model_Acl extends Zend_Acl { public function __construct() { /* * 第一次添加权限 "guest" ，支持查看所有的内容 */ $this->addRole(new Zend_Acl_Role('guest')); /* * 添加 'user' 组权限，权限大于 &#8230; <a href="http://www.neatcn.com/show-35-1.shtml">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>如果不想用rbac那么，简单权限管理ACL，应该是最方便的了。简要说一下原理吧。。<br />
这个文件是放在/application/models/目录下的Acl.php，调用的时候就直接 </p>
<pre class="brush:php">
$identity = Zend_Auth::getInstance()->getIdentity();
$acl = new Application_Model_Acl();
//然后判断
if( $acl->isAllowed( $identity['Role'] , 'xxxxx' ,'yyyy' )); //xxxx是controller名，yyyy是controller里的action名称。不用额外加action。。。
</pre>
<pre class="brush:php">
class Application_Model_Acl extends Zend_Acl
{

	public function __construct()
	{
		/*
		 *  第一次添加权限 "guest" ，支持查看所有的内容
		 */
		$this->addRole(new Zend_Acl_Role('guest'));

		/*
		 * 添加 'user' 组权限，权限大于 guest
		 * 用户组能够发表回复
		 */
		$this->addRole(new Zend_Acl_Role('user'), 'guest');

		/*
		 * 添加一个auth组
		 * auth用户权限基于user,并且可以发表文章
		 */
		$this->addRole(new Zend_Acl_Role('auth'), 'user');

		/*
		 * 添加admin组权限，可以做任何事情
		 */
		$this->addRole(new Zend_Acl_Role('admin'), 'blogger');

		//添加允许使用的Resource（也就是controller名啦），这是posts controller
		$this->add(new Zend_Acl_Resource('posts'));

		//添加允许使用的Resource（也就是controller名啦），这是comments controller
		$this->add(new Zend_Acl_Resource('comments'));

		//最后，添加权限，guest用户组可以执行posts controller下的view方法
		$this->allow('guest', 'posts', 'view');

		//User组可以执行 comments controller下的Add 方法
		$this->allow('user', 'comments', 'add');

		// auth 除了上面的功能外还能够支持 posts controller 中的Edit和add方法
		$this->allow('auth', 'posts', 'edit');
		$this->allow('auth', 'posts', 'add');
	}

}
</pre>
<p>是不是很方便？ACL就是这样的方便 。。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neatcn.com/show-35-1.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

