Having multiple instances of Zend Navigation in a single View

so I have been playing around with the Zend Framework rather extensively over the past few weeks and it has been a very rewarding experience.

I am posting this here because it was a bit difficult finding a work around for the issue I describe below.

Zend Navigation had been giving me a lot of problems especially because I could not get the Navigation object passed to my view object to render two different navigation configs. The top menu which remains the same for all pages and is rendered in my layout and other sub menus rendered in my individual view pages.

Now getting to it:

in my bootstrap I initialise my navigation with something like this.

$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
 $miscNavConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/miscnavigation.xml', 'nav');
 $navigation = new Zend_Navigation($config);
 $miscNavigation = new Zend_Navigation($miscNavConfig);
 Zend_Registry::set(Zend_Navigation, $navigation);
 Zend_Registry::set('MiscNavigation', $miscNavigation);
 $view->navigation($navigation);

Now  lines 2, 4, and 6 are the new lines I have added for additional nagivation. I beleive you should be able to add new configurations as you move along if you need to.

The next bit was retrieving the sub navigation in my controller:

$miscNavigation = Zend_Registry::get('MiscNavigation');
$this->view->miscnavigation = $miscNavigation;

You can do this in your view but because I route several of my views through this controller I want to have to do it only once.

And finally in my view:

$options = array('ulClass' => 'submenu');
echo($this->navigation()->menu()->renderMenu($this->miscnavigation, $options));

Bear in mind that I use the renderMenu method instead of passing $this->miscnavigation into the menu method. If you do that you will overwrite any other instances of menu you have on the page with the miscnavigation object.

Too Long

So over the past few months I have not written anything here at all. Simply because I have been really busy with quite a few things and I am working under the assumption that I will be really busy for a while to come. I got some time now and I thought I should write something here.

What has got me busy over the past few weeks has been a Research Proposal. This is for a PhD and I really hope to get a place in the 2010/2011 academic year. It is obviously going to be in computing (Web Services and Quality of Service).

I have also been testing out all these new web 2.0 technologies and all that comes with it. The first was seesmic: I even got the blackberry app and all worked for a bit and then I got tired of it. I believe it was really about the feel of the application rather than how it worked, because I think it works fine I still prefer ubertwitter for those purposes.

Then I thought to myself, my facebook profile: I don’t remember the last time I actively updated that. At first I had my status automatically updated through my twitter updates. I am not sure at which point that bridge was hacked but I started updating my facebook pages in Japanese and trying to sell anyone who bothered to translate what was on there a wii or something like that. Goes without saying… I burnt that bridge really quickly – uninstalled my facebook-twitter app and basically haven’t used that profile for anything besides testing facebook integration with mokocharlie.com version 3 (which is coming out soon by the way).

I decided then to try a cross between my twitter account and a blog in the present incarnation it’s a service called tumblr. I even altered my A record so that this blog was redirected to my tumblr blog. This infatuation lasted for all of 5 minutes playing around with it. What really turned me off the whole thing were the buttons on the top of the blog. They were constantly telling people to join tumblr or subscribe to my blog. I don’t mind having those buttons on my blog. I just want the option to do whatever I want with my page especially when it’s as themable as tumblr is. They even make your profile picture into a favicon and all that, I was impressed with the web 2.0 ruby on rails feel to the whole thing. I just wasn’t that sold…

Finally traded in my Wii, I love the machine and it works beautifully since the day I bought it (the day it was launched), I have had absolutely no issues with it at all. It’s been stable, fun and exhilarating. The problem I have with it though is that week in week out I see all these awesome titles released to the darkside (PS3 and XBox 360) and I feel like I’m missing out on all the action. I have always been a Nintendo fan and I believe if they were to release a higher spec version of the console that was actually able to compete with all those eye watering titles I will get myself one. For now however, I want to play some God Of War 3. And that’s not on the Wii nor on the XBox so it is with a saddened heart that I say this that I am looking to get a PS3 sometime over the next few days at the expense of my Wii — sad times.

a note on json_de/encode

I just thought I should quickly post this note simply because I know a few people might have problems with parsing it with the above functions.

I would like first to say that json_encode and json_decode are PHP 5.2.0+ methods of parsing and dealing with Javascript Simple Object Notation. basically looks a bit like this {“key”:”value”}. The idea is to be able to do useful things with objects like these and stepping through the key and value pairs while doing something with them.

The problem however is you sometimes get JSON sent as a string through an HTTP method like $_POST and the quotes in there are automatically (well in my case). escaped with backslashes like this {\”jsonkey\”:\”jsonvalue\”}. Before you actually call json_decode on your json data use the built in stripslashes function first. so your code should look like this in one line

$json_array = json_decode(stripslashes($jsonObject));

hope this helps someone.