I have been using zend_acl and Zend_Navigation together on my project currently and it seems to work correctly. I am how ever using a lot of ajax in my site and have made a login with jqModal and jQuery which logs in users without reloading the current page and have the need to reload the navigation as well. I have so far got it working but the navigation being return is all the links with the visible field as true which is incorrect. For example when I am logged in as a user the login link should not be visible.
Any help would be appreciated. My code below for Action, JavaScript function and Json returned.
======================================================= current role = admins
// CONTROLLER ACTION
public function getnavigationjsonAction() { //$view->navigation($container)->setAcl($this->_acl)->setRole(Zend_Registry::get('role')); // echo $this->navigation()->menu(); $navigation = $this->getView()->navigation()->setAcl($this->_acl)->setRole(Zend_Registry::get('role')); //die(Zend_Registry::get('role')); //die($this->_acl); $this->_helper->json($navigation->toArray()); }
// JAVASCRIPT FUNCTION
function reloadNavigationMenu() { //alert('reloading navigation'); $.ajax( { url : "/default/ajax/getnavigationjson", type : "POST", cache : false, async : false, data : "format=json", success : function(data) { var html=''; console.log(data);
$.each(data, function(i) { if(data[i].visible === true) { //console.log(data[i]); html+='
}
// RETURN JSON data from controller
[ { "action" : "index", "active" : false, "class" : null, "controller" : "admin", "id" : null, "label" : "Admin Section", "module" : "admin", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : "index", "rel" : [ ], "reset_params" : true, "resource" : "admin:admin", "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true }, { "action" : "index", "active" : false, "class" : null, "controller" : "index", "id" : null, "label" : "Home", "module" : "default", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : null, "rel" : [ ], "reset_params" : true, "resource" : null, "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true }, { "action" : "index", "active" : false, "class" : null, "controller" : "index", "id" : null, "label" : "News", "module" : "news", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : "index", "rel" : [ ], "reset_params" : true, "resource" : "news:index", "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true }, { "action" : "index", "active" : false, "class" : null, "controller" : "index", "id" : null, "label" : "Tutorials", "module" : "tutorials", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : "index", "rel" : [ ], "reset_params" : true, "resource" : "tutorials:index", "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true }, { "action" : "about", "active" : false, "class" : null, "controller" : "index", "id" : null, "label" : "About", "module" : "default", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : "about", "rel" : [ ], "reset_params" : true, "resource" : "default:index", "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true }, { "action" : "comments", "active" : false, "class" : null, "controller" : "index", "id" : null, "label" : "Comments", "module" : "default", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : "comments", "rel" : [ ], "reset_params" : true, "resource" : "default:index", "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true }, { "action" : "index", "active" : false, "class" : null, "controller" : "contact", "id" : null, "label" : "Contact", "module" : "default", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : "index", "rel" : [ ], "reset_params" : true, "resource" : "default:contact", "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true }, { "action" : "login", "active" : false, "class" : null, "controller" : "auth", "id" : null, "label" : "Login", "module" : "default", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : "login", "rel" : [ ], "reset_params" : true, "resource" : "default:auth", "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true }, { "action" : "logout", "active" : false, "class" : null, "controller" : "auth", "id" : null, "label" : "Logout", "module" : "default", "order" : null, "pages" : [ ], "params" : [ ], "privilege" : "logout", "rel" : [ ], "reset_params" : true, "resource" : "default:auth", "rev" : [ ], "route" : null, "target" : null, "title" : null, "type" : "Zend_Navigation_Page_Mvc", "visible" : true } ]
This is when I am currently logged in as admin and the links for login should be hidden but its not. This looks like the ACL is not being properly assigned to the navigation.