this post is more of a personal best practice and thought to share it with you guys. I like to do things this way, and think this is the best aproach, but i might be wrong and i would like your feedback on this .
So in Zend Framework first of all you are recommended to always use the routers assemble method to generate the Urls. Wich is very good since you will then have an easy way of updating an URL, for example when the SEO guy tells you to switch 2 url params around.
The problem is where you place your call to the router ?
One way to go about it is to place it in the controller, or in the view. But i think that is not the best ideea since this would mean in case you would want to change the route, the name for example, you would need to change it in all the places you made it.
A second choice would be to have the router call in a function somewhere that you would call from everywhere you would want the URL generated. But that seems to me like an extra layer.
Almost all the time that URL is related to a model. For example if u have an article model. then you could make a method buildUrl :
public function buildUrl()
$router = Zend_Controller_Front::getInstance()->getRouter();
$url = $router->assemble(
‘article_id’ => $this->id,
and then in your controllers and views you would just do:
which looks nicer and you are keeping the call to the router in one place.
Thats about it, i know this might look like pretty simple stuff for most of you, but i hope some will find this useful.