Featured post
json - Zend_Navigation, Zend_ACL + Roles not filtering correctly through an Ajax request -
i have been using zend_acl , zend_navigation on project , seems work correctly. how ever using lot of ajax in site , have made login jqmodal , jquery logs in users without reloading current page , have need reload navigation well. have far got working navigation being return links visible field true incorrect. example when logged in user login link should not visible.
any appreciated. code below action, javascript function , 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 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 when logged in admin , links login should hidden not. looks acl not being assigned navigation.
i think zend_navigation uses acl determine if page should visible during render time. doesn't alter navigation objects when pass acl object it.
you need different approach if want create custom navigation container reduced acl - maybe extending zend navigation classes , add appropriate methods.
- Get link
- X
- Other Apps
Comments
Post a Comment