<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Zendcasts Forum / Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
		<link>http://www.zendcasts.com/forum/viewtopic.php?id=97</link>
		<description><![CDATA[The most recent posts in Integrating ACL with Zend_Navigation using view partials for rendering.]]></description>
		<lastBuildDate>Sun, 21 Nov 2010 01:31:42 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=1185#p1185</link>
			<description><![CDATA[<p>hi i tried the code ryan.horn but I get an error I work with modules</p><p>code here</p><p>//In your layout-layout.phtml</p><p>&lt;?php <br />$filteringMenu = $this-&gt;navigation()-&gt;FilteringMenu();<br />$filteringMenu-&gt;setPartial(array(&#039;menu.phtml&#039;,&#039;default&#039;));<br />echo $filteringMenu;<br />?&gt;</p><p>// In your default-view-script-menu.phtml<br />&lt;?php <br />$this-&gt;addHelperPath(&#039;Config&#039;, &#039;Config_&#039;);</p><br /><p>//In config-FilteringMenu.php<br />&lt;?php <br />class Config_FilteringMenu extends Zend_View_Helper_Navigation_Menu {</p><br /><p>and this is the error that the browser shows me:</p><p>Fatal error: Uncaught exception &#039;Zend_Navigation_Exception&#039; with message &#039;Bad method call: Unknown method Zend_Navigation::FilteringMenu&#039;</p>]]></description>
			<author><![CDATA[dummy@example.com (limkin)]]></author>
			<pubDate>Sun, 21 Nov 2010 01:31:42 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=1185#p1185</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=1164#p1164</link>
			<description><![CDATA[<p>ryan.horn<br />I would like to explain me more detail<br />with the same problem I want to make a custom menu with ACL<br />I need your help please let me know exactly<br />that part add the code you wrote</p><p>thanks</p>]]></description>
			<author><![CDATA[dummy@example.com (limkin)]]></author>
			<pubDate>Fri, 12 Nov 2010 02:01:48 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=1164#p1164</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=887#p887</link>
			<description><![CDATA[<div class="quotebox"><cite>ryan.horn wrote:</cite><blockquote><div><p>I solved this by writing my own navigation menu view helper that extends the one included with the framework. It could go further with optimization, but this is at least working.</p><p>Here&#039;s the code:</p></div></blockquote></div><p>Thanks for putting this code up, I just tried it out and it worked perfectly for me <img src="http://www.zendcasts.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (chrismacp)]]></author>
			<pubDate>Sun, 06 Jun 2010 16:18:27 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=887#p887</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=663#p663</link>
			<description><![CDATA[<p>Well thanks for your answers and sorry for the late those thanks come... <br />I know that Page_Uri was intended (not sure if it&#039;s the right word Frenchy inside) for external URL. But i choose to use it because i have a sort of link generator in my CMS and it was more easy to handle &quot;user typed&quot; url (that could be internal or not) and i failed trying to reverse those url to the mvc style for the case they were internal ones. I think i must digg harder and found a way to do that it will be far better.</p>]]></description>
			<author><![CDATA[dummy@example.com (T_bo)]]></author>
			<pubDate>Thu, 18 Feb 2010 12:48:02 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=663#p663</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=611#p611</link>
			<description><![CDATA[<p>Zend_Navigation_Page_Uri was designed to be used for external links. Conceptually an external link cannot be &quot;active&quot; and has no way of checking (versus Zend_Navigation_Page_Mvc, which has access to the request object in order to determine the current module/controller/action). Use Zend_Navigation_Page_Mvc if you want the navigation to automatically detect and set the active state for a page.</p>]]></description>
			<author><![CDATA[dummy@example.com (ryan.horn)]]></author>
			<pubDate>Thu, 04 Feb 2010 17:06:42 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=611#p611</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=610#p610</link>
			<description><![CDATA[<p>I may have explain a bit more the context. <br /> isActive() is working for mvc page only for uri page&#160; the ref says <br /></p><div class="quotebox"><blockquote><div><p>Zend_Navigation_Page_Uri will not try to determine whether it should be active when calling $page-&gt;isActive(). It merely returns what currently is set, so to make a URI page active you have to manually call $page-&gt;setActive() or specifying active as a page option when constructing.</p></div></blockquote></div><p>So even if your page uri for example : <br />$page = new Zend_Navigation_Page_uri(array(<br />&#160; &#160; &#039;label&#039; =&gt; &#039;Home&#039;,<br />&#160; &#160; &#039;uri&#039;&#160; &#160;=&gt; &#039;<a href="http://www.example.com/">http://www.example.com/</a>&#039;<br />));</p><p>isActive() doesn&#039;t work for your home page</p><p>you have to make it manualy active and reflect the state on all the navigation every time the page change...</p>]]></description>
			<author><![CDATA[dummy@example.com (T_bo)]]></author>
			<pubDate>Thu, 04 Feb 2010 15:22:07 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=610#p610</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=609#p609</link>
			<description><![CDATA[<p>$page-&gt;isActive() should work...</p>]]></description>
			<author><![CDATA[dummy@example.com (Jon Lebensold)]]></author>
			<pubDate>Thu, 04 Feb 2010 14:59:08 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=609#p609</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=608#p608</link>
			<description><![CDATA[<p>Nice to know it&#039;s a feature not implemented in the original Zend_Navigation.<br />I have to use a check in my partial last time I use Zend_Navigation and found that very &quot;inadequate&quot;.</p><p>Thanks for the solution came with.</p><p>Speaking of Zend_Navigation is there a way to know if a &quot;link&quot; is active (not by setting it but in sort of automatic way) it will be very helpfull for design issue.</p>]]></description>
			<author><![CDATA[dummy@example.com (T_bo)]]></author>
			<pubDate>Thu, 04 Feb 2010 14:38:15 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=608#p608</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=558#p558</link>
			<description><![CDATA[<p>@ryan.horn</p><p>very nice one. What I do miss in your description is how you shaped you default-navigation.phtml where I assume you put your own classes. </p><p>Can I ask you to supply the markup for that partial view script as well please to complete your solution? Thanks.</p>]]></description>
			<author><![CDATA[dummy@example.com (Hanno)]]></author>
			<pubDate>Mon, 18 Jan 2010 19:59:00 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=558#p558</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=445#p445</link>
			<description><![CDATA[<p>@iwarner what do you mean about the forum? did you have trouble activating your account?</p>]]></description>
			<author><![CDATA[dummy@example.com (Jon Lebensold)]]></author>
			<pubDate>Fri, 04 Dec 2009 04:39:53 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=445#p445</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=444#p444</link>
			<description><![CDATA[<p>Activating subscription - forum page offers no link to do this??</p>]]></description>
			<author><![CDATA[dummy@example.com (iwarner)]]></author>
			<pubDate>Fri, 04 Dec 2009 04:07:12 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=444#p444</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=443#p443</link>
			<description><![CDATA[<p>Hi I use this:</p><p>Notice the : $this-&gt;navigation()-&gt;accept($page)<br />Seems to work with all the tests I have done</p><p>Had to do all this though cause I needed an extra Span to control tabs display - annnoying!</p><p>[code=php]<br />&lt;?php</p><p>/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */</p><p>/**<br /> * Navigational Menu partial to output the navigation correctly<br /> *<br /> * &lt;code&gt;<br /> * // User in the general Layout<br /> * echo $this-&gt;navigation()-&gt;menu()-&gt;setPartial(array(&#039;menu.phtml&#039;, &#039;default&#039;));<br /> * &lt;/code&gt;<br /> *<br /> * @category&#160; CodeBlender<br /> * @package&#160; &#160;Theme<br /> * @copyright Copyright (c) 2000-2009 Triangle Solutions Ltd. (<a href="http://www.triangle-solutions.com/">http://www.triangle-solutions.com/</a>)<br /> * @license&#160; &#160;<a href="http://codeblender.net/license">http://codeblender.net/license</a><br /> * @version&#160; &#160;SVN: $Id: $<br /> */</p><p>// Set the filter option for the Active navigation<br />$this-&gt;navigation()-&gt;findByResource(<br />&#160; Zend_Controller_Front::getInstance()-&gt;getRequest()-&gt;module .<br />&#160; Zend_Controller_Front::getInstance()-&gt;getRequest()-&gt;controller<br /> );<br />?&gt;</p><p>&lt;ul&gt;</p><p>&lt;?php<br />// Loop through the container<br />foreach ($this-&gt;container as $page) {</p><p>&#160; &#160; // Check whether the page is set as Visible and also it is accepted through the ACL<br />&#160; &#160; if ($page-&gt;isVisible() &amp;&amp; $this-&gt;navigation()-&gt;accept($page)) {</p><p>&#160; &#160; &#160; &#160; // Create the class to use if the tab is active<br />&#160; &#160; &#160; &#160; $liClass = $page-&gt;isActive(false) ? &#039; class=&quot;active&quot;&#039; : &#039;&#039;;</p><p>&#160; &#160; &#160; &#160; // HTML to generate the tabs<br />?&gt;<br />&#160; &#160; &#160; &#160; &lt;li&lt;?php echo $liClass; ?&gt;&gt;<br />&#160; &#160; &#160; &#160; &#160; &lt;a href=&quot;&lt;?php echo $page-&gt;getHref(); ?&gt;&quot; title=&quot;&lt;?php echo $page-&gt;getTitle(); ?&gt;&quot;&gt;<br />&#160; &#160; &#160; &#160; &#160; &lt;span&gt;&lt;?php echo $page-&gt;getLabel() ?&gt;&lt;/span&gt;&lt;/a&gt;<br />&#160; &#160; &#160; &#160; &lt;/li&gt;<br />&lt;?php<br />&#160; &#160; }<br />}<br />?&gt;</p><p>&lt;/ul&gt;<br />[/code]</p>]]></description>
			<author><![CDATA[dummy@example.com (iwarner)]]></author>
			<pubDate>Fri, 04 Dec 2009 04:05:13 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=443#p443</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=408#p408</link>
			<description><![CDATA[<p>I solved this by writing my own navigation menu view helper that extends the one included with the framework. It could go further with optimization, but this is at least working.</p><p>Here&#039;s the code:</p><p>[code=php]<br />class AOneFiveThree_View_Helper_Navigation_FilteringMenu extends Zend_View_Helper_Navigation_Menu {</p><p>&#160; &#160; /**<br />&#160; &#160; &#160;* View helper entry point:<br />&#160; &#160; &#160;* Retrieves helper and optionally sets container to operate on<br />&#160; &#160; &#160;*<br />&#160; &#160; &#160;* @param&#160; Zend_Navigation_Container $container&#160; [optional] container to<br />&#160; &#160; &#160;*&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;operate on<br />&#160; &#160; &#160;* @return Zend_View_Helper_Navigation_Menu&#160; &#160; &#160; fluent interface,<br />&#160; &#160; &#160;*&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;returns self<br />&#160; &#160; &#160;*/<br />&#160; &#160; public function filteringMenu(Zend_Navigation_Container $container = null) {<br />&#160; &#160; &#160; &#160; if (null !== $container) {<br />&#160; &#160; &#160; &#160; &#160; &#160; $this-&gt;setContainer($container);<br />&#160; &#160; &#160; &#160; }</p><p>&#160; &#160; &#160; &#160; return $this;<br />&#160; &#160; }</p><p>&#160; &#160; /**<br />&#160; &#160; &#160;* Renders menu<br />&#160; &#160; &#160;*<br />&#160; &#160; &#160;* Implements {@link Zend_View_Helper_Navigation_Helper::render()}.<br />&#160; &#160; &#160;*<br />&#160; &#160; &#160;* If a partial view is registered in the helper, the menu will be rendered<br />&#160; &#160; &#160;* using the given partial script. Unlike<br />&#160; &#160;&#160; * Zend_View_Helper_Navigation_Menu::render(), pages will be filtered based<br />&#160; &#160;&#160; * on visibility and ACL before being passed to the view partial script.<br />&#160; &#160;&#160; * If no partial is registered, the menu will be rendered as an &#039;ul&#039; element<br />&#160; &#160;&#160; * by the helper&#039;s internal method.<br />&#160; &#160; &#160;*<br />&#160; &#160; &#160;* @see renderPartial()<br />&#160; &#160; &#160;* @see renderMenu()<br />&#160; &#160; &#160;*<br />&#160; &#160; &#160;* @param&#160; Zend_Navigation_Container $container&#160; [optional] container to<br />&#160; &#160; &#160;*&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;render. Default is to<br />&#160; &#160; &#160;*&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;render the container<br />&#160; &#160; &#160;*&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;registered in the helper.<br />&#160; &#160; &#160;* @return string&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; helper output<br />&#160; &#160; &#160;*/<br />&#160; &#160; public function render(Zend_Navigation_Container $container = null) {<br />&#160; &#160; &#160; &#160; if (null === $container) {<br />&#160; &#160; &#160; &#160; &#160; &#160; $container = $this-&gt;getContainer();<br />&#160; &#160; &#160; &#160; }</p><p>&#160; &#160; &#160; &#160; if ($partial = $this-&gt;getPartial()) {<br />&#160; &#160; &#160; &#160; &#160; &#160; return $this-&gt;__filterRestrictedPages($container)<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; -&gt;renderPartial($container, $partial);<br />&#160; &#160; &#160; &#160; } else {<br />&#160; &#160; &#160; &#160; &#160; &#160; return $this-&gt;renderMenu($container);<br />&#160; &#160; &#160; &#160; }<br />&#160; &#160; }</p><p>&#160; &#160; /**<br />&#160; &#160;&#160; * Filters out invisible and ACL based restricted pages<br />&#160; &#160;&#160; *<br />&#160; &#160;&#160; * @access protected<br />&#160; &#160;&#160; * @param Zend_Navigation_Container $container<br />&#160; &#160;&#160; * @return Zend_Navigation_Container<br />&#160; &#160;&#160; */<br />&#160; &#160; protected function __filterRestrictedPages(Zend_Navigation_Container $container) {<br />&#160; &#160; &#160; &#160; // Need to clone the container as we will be removing pages from the<br />&#160; &#160; &#160; &#160; // actual container within the recursive iterator loop. Removing<br />&#160; &#160; &#160; &#160; // elements from the object we&#039;re iterating over *while* iterating will<br />&#160; &#160; &#160; &#160; // trip up the iterator.<br />&#160; &#160; &#160; &#160; $iterator = new RecursiveIteratorIterator(clone $container,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; RecursiveIteratorIterator::SELF_FIRST);</p><p>&#160; &#160; &#160; &#160; foreach ($iterator as $page) {<br />&#160; &#160; &#160; &#160; &#160; &#160; /* @var $page Zend_Navigation_Page_Mvc */<br />&#160; &#160; &#160; &#160; &#160; &#160; if (!$this-&gt;accept($page)) {<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $container-&gt;removePage($page);<br />&#160; &#160; &#160; &#160; &#160; &#160; }<br />&#160; &#160; &#160; &#160; }</p><p>&#160; &#160; &#160; &#160; return $this;<br />&#160; &#160; }<br />[/code]</p><p>In order to use the custom menu, you need to add the helper path to your view (replace the AOneFiveThree with your own library or application namespace):</p><p>[code=php]<br />// In your view-script.phtml<br />$this-&gt;addHelperPath(&#039;AOneFiveThree/View/Helper/Navigation&#039;, &#039;AOneFiveThree_View_Helper_Navigation_&#039;);<br />[/code]</p><p>Then, to load the helper, tell it to user a view partial for rendering and render it out:<br />[code=php]<br />$filteringMenu = $this-&gt;navigation()-&gt;FilteringMenu();<br />$filteringMenu-&gt;setPartial(&#039;partials/default-navigation.phtml&#039;);<br />echo $filteringMenu;<br />[/code]</p><br /><p>And of course, prior to all of this, you need to expose your navigation object, ACL object and the current role to the navigation helper somewhere (probably your bootstrap or a controller plugin). Each page in your navigation object needs to have a resource defined that matches the resources in your ACL for the menu helper to properly filter out restricted pages. The framework reference guide goes over all of this.</p><p>[code=php]<br />// Assuming $navigation is your navigation object</p><p>// Expose the navigation object to the navigation view helper<br />Zend_Layout::getMvcInstance()<br />&#160; &#160; &#160; &#160;&#160; &#160; -&gt;getView()<br />&#160; &#160; &#160; &#160;&#160; &#160; -&gt;navigation($navigation);</p><p>// Assuming $acl is your $acl object and $role is the current ACL role in use</p><p>// Expose the acl and role to the view navigation helper so it knows which items to<br />// filter<br />Zend_Layout::getMvcInstance()<br />&#160; &#160; &#160; &#160;&#160; &#160; -&gt;getView()<br />&#160; &#160; &#160; &#160;&#160; &#160; -&gt;navigation()<br />&#160; &#160; &#160; &#160;&#160; &#160; -&gt;setAcl($acl)<br />&#160; &#160; &#160; &#160;&#160; &#160; -&gt;setRole($role);<br />[/code]</p><p>I can explain this in more detail if anyone wants, just let me know.</p><p>Edit: I realize this only works on a shallow navigation</p>]]></description>
			<author><![CDATA[dummy@example.com (ryan.horn)]]></author>
			<pubDate>Sat, 28 Nov 2009 19:24:37 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=408#p408</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=380#p380</link>
			<description><![CDATA[<p>I have ACL working with Zend_Navigation without using view partials. The problem is that the default rendering of Zend_Navigation is not as flexible as I&#039;d like (it doesn&#039;t allow you to customize the individual &lt;li&gt; elements), so I need to use a view partial to render it out myself. This is done using the navigation menu view helper and invoking the &quot;setPartial()&quot; method, passing my partial view path in (see <a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation.menu).">http://framework.zend.com/manual/en/zen … ion.menu).</a></p><p>The problem is that when you tell it to use a partial, it skips the default rendering method (renderMenu()), which happens to also contain the logic for filtering out menu items based on ACL (take a look in Zend/View/Helper/Navigation/Menu.php). So the logic for filtering out the items need to be reimplemented in the view partial (or somewhere else). Seems like there was debate about this in the initial proposal (<a href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Navigation+-+Robin+Skoglund">http://framework.zend.com/wiki/display/ … n+Skoglund</a>). I guess my big question is how to re-implement that ACL logic.</p><p>For reference, here&#039;s how I have my ACL and Navigation setup in my application:</p><p>[code=php]<br />Bootstrap.php<br />...<br />&#160; &#160; protected function _initAcl() {<br />&#160; &#160; &#160; &#160; ...</p><p>&#160; &#160; &#160; &#160; $acl = new Zend_Acl();<br />&#160; &#160; &#160; &#160; $aclData = new Zend_Config_Xml(APPLICATION_PATH . &#039;/configs/acl.xml&#039;, $module);<br />&#160; &#160; &#160; &#160; foreach ($aclData-&gt;roles-&gt;role as $role) {<br />&#160; &#160; &#160; &#160; &#160; &#160; $acl-&gt;addRole(new Zend_Acl_Role($role));<br />&#160; &#160; &#160; &#160; }</p><p>&#160; &#160; &#160; &#160; foreach ($aclData-&gt;resources-&gt;resource as $resource) {<br />&#160; &#160; &#160; &#160; &#160; &#160; $acl-&gt;addResource(new Zend_Acl_Resource($module . &#039;.&#039; . $resource));<br />&#160; &#160; &#160; &#160; }</p><p>&#160; &#160; &#160; &#160; // If an allow whitelist is specified, process<br />&#160; &#160; &#160; &#160; if (!empty($aclData-&gt;whitelist-&gt;allow)) {</p><p>&#160; &#160; &#160; &#160; &#160; &#160; // Convert it to an array<br />&#160; &#160; &#160; &#160; &#160; &#160; $whitelist = $aclData-&gt;whitelist-&gt;allow-&gt;toArray();</p><p>&#160; &#160; &#160; &#160; &#160; &#160; // If there&#039;s more than one allow rule, iterate over and process<br />&#160; &#160; &#160; &#160; &#160; &#160; // each<br />&#160; &#160; &#160; &#160; &#160; &#160; if (isset($whitelist[0])) {<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; foreach ($whitelist as $allow) {<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $acl-&gt;allow($allow[&#039;role&#039;], $module . &#039;.&#039; . $allow[&#039;resource&#039;]);<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }<br />&#160; &#160; &#160; &#160; &#160; &#160; } else {<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $acl-&gt;allow($whitelist[&#039;role&#039;], $module . &#039;.&#039; . $whitelist[&#039;resource&#039;]);<br />&#160; &#160; &#160; &#160; &#160; &#160; }<br />&#160; &#160; &#160; &#160; }<br />&#160; &#160; &#160; &#160; // If a blacklist is specified, process<br />&#160; &#160; &#160; &#160; if (!empty($aclData-&gt;blacklist-&gt;allow)) {</p><p>&#160; &#160; &#160; &#160; &#160; &#160; // Convert it to an array<br />&#160; &#160; &#160; &#160; &#160; &#160; $blacklist = $aclData-&gt;blacklist-&gt;allow-&gt;toArray();</p><p>&#160; &#160; &#160; &#160; &#160; &#160; // If there&#039;s more than one allow rule, iterate over and process<br />&#160; &#160; &#160; &#160; &#160; &#160; // each<br />&#160; &#160; &#160; &#160; &#160; &#160; if (isset($blacklist[0])) {<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; foreach ($blacklist as $deny) {<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $acl-&gt;deny($deny[&#039;role&#039;], $module . &#039;.&#039; . $deny[&#039;resource&#039;]);<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }<br />&#160; &#160; &#160; &#160; &#160; &#160; } else {<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $acl-&gt;deny($blacklist[&#039;role&#039;], $module . &#039;.&#039; . $blacklist[&#039;resource&#039;]);<br />&#160; &#160; &#160; &#160; &#160; &#160; }<br />&#160; &#160; &#160; &#160; }</p><p>&#160; &#160; &#160; &#160; // Store the acl in the registry<br />&#160; &#160; &#160; &#160; Zend_Registry::set(&#039;acl&#039;, $acl);<br />&#160; &#160; &#160; &#160; return $acl;<br />&#160; &#160; }</p><p>...</p><p>&#160; &#160; protected function _initNavigation() {<br />&#160; &#160; &#160; &#160; ...</p><p>&#160; &#160; &#160; &#160; // Load the current module&#039;s navigation section within the navigation<br />&#160; &#160; &#160; &#160; // config<br />&#160; &#160; &#160; &#160; $config = new Zend_Config_Xml(APPLICATION_PATH . &#039;/configs/navigation.xml&#039;, MODULE);</p><p>&#160; &#160; &#160; &#160; // Create a new navigation object<br />&#160; &#160; &#160; &#160; $navigation = new Zend_Navigation($config);</p><p>&#160; &#160; &#160; &#160; // Set the navigation object to the view<br />&#160; &#160; &#160; &#160; Zend_Layout::getMvcInstance()<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160; &#160; &#160;-&gt;getView()<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; -&gt;navigation($navigation);<br />&#160; &#160; }[/code]<br />Controller_Plugin_Init.php (this is a controller plugin that handles identity retrieval and user role)<br />[code=php]<br />&#160; &#160; public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {<br />&#160; &#160; &#160; &#160; ...</p><p>&#160; &#160; &#160; &#160; $acl = Zend_Registry::get(&#039;acl&#039;);</p><p>&#160; &#160; &#160; &#160; // Expose the acl to the view navigation so it knows which items to<br />&#160; &#160; &#160; &#160; // render<br />&#160; &#160; &#160; &#160; Zend_Layout::getMvcInstance()<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160; &#160; -&gt;getView()<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160; &#160; -&gt;navigation()<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160; &#160; -&gt;setAcl($acl)<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160; &#160; -&gt;setRole($user-&gt;Role-&gt;name);<br />&#160; &#160; }[/code]<br />And in my layout script<br />[code=php]<br />...<br />echo $this-&gt;navigation()-&gt;menu();<br />...[/code]</p>]]></description>
			<author><![CDATA[dummy@example.com (ryan.horn)]]></author>
			<pubDate>Mon, 23 Nov 2009 17:51:25 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=380#p380</guid>
		</item>
		<item>
			<title><![CDATA[Re: Integrating ACL with Zend_Navigation using view partials for rendering]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=378#p378</link>
			<description><![CDATA[<p>Hello Ryan,</p><p>do you refer to this: <a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation.acl">http://framework.zend.com/manual/en/zen … gation.acl</a></p><p>I had issues using the &quot;integrated&quot; ACL functionality in combination with Zend_Navigation.</p><p>Using resources in navigation.xml and giving them access through ACL did not work for me... At least I could not make it work.</p><p>How does your approach look like?</p><p>Best, Udo</p>]]></description>
			<author><![CDATA[dummy@example.com (udo)]]></author>
			<pubDate>Mon, 23 Nov 2009 14:08:06 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=378#p378</guid>
		</item>
	</channel>
</rss>

