Zend Framework – View – $this->url()

Been using ZF a lot. It hasn’t amazed me because even though it’s really powerful it’s still very complicated to achieve simple task and the official documentation is very very messy.

Anyway, I have this layout for a project with a main menu.

Each of the menu options link to a different controller, instead of hard coding the menu links I used ZF url helper so for every link I was using something like this:

$this->url(array('controller'=>'console','action'=>'index'));

Which when ran gave me the following link

/[project_folder]/public/console

This looked just fine. Later on I created a product’s catalogue and from there a link to see a product’s detail. The link was:

$this->url(array('controller'=>'catalogue','action'=>'details','pid'=>[product_id]));

Everything worked just fine so I clicked the products details link. Everything looked fine. Then I clicked one of the main menu links to get to another section of the web page and then a bug popped.

For some reason all the links where appended with the GET parameters so when I clicked on the info link it took me to

/[project_folder]/public/info/pid/[product_id]

And obviously I was getting an error because there was no ‘pid’ action for the ‘info’ controller.

I searched and read a couple of google results, give the documentation a try (it sucks) and after a while I ended up in a simple blog entry with the solution.

I only needed to change my code to this:

$this->url(array('controller'=>'console','action'=>'index'),null,true);

Now GET params are not appended to the URL’s and everything works fine 😀

Tags: ,

Leave a Reply

You must be logged in to post a comment.