Jump to content

ZF Routing Insanity


delboy1978uk

Recommended Posts

Hi guys, I'm going through the Apress book "beginning zend framework", and now i'm stuck lol

 

i have various actions for an artist controller, one of which is:

http://localhost/artist/new (adds new artist)

 

the book then explains how to enable routing:

http://localhost/artist/thebeatles (actually goes to artist/profile action)

 

Here's the routing code:

 

/** Routing Info **/

$FrontController = Zend_Controller_Front::getInstance();

$Router = $FrontController->getRouter();

 

$Router->addRoute("artistprofile", new Zend_Controller_Router_Route(

 

"artist/:artistname", array

("artistname" => "The Smiths",

"controller" => "artist",

"action" => "profile" )

));

 

However, since enabling this routing, even artist/new gets routed to artist/profile! Surely it only routes if the action doesn't exist!

The book doesn't even recognise that theres a problem, but then the book is for v1.8, and i have v1.10

Link to comment
https://forums.phpfreaks.com/topic/213964-zf-routing-insanity/
Share on other sites

"artistname" => "The Smiths"

 

Shouldn't be there. You should provide this value when you use the Route like:

 

print $this->url(array('artistname' => 'The Smiths'), 'artistprofile');

 

Read the errata if you get stuck chances are someone found a problem in the code and reported it.

Link to comment
https://forums.phpfreaks.com/topic/213964-zf-routing-insanity/#findComment-1113591
Share on other sites

Thanks for your reply!

 

I removed the line, and now it goes to the index controller when i dont type an action name :-)

however if I type in /add or /edit etc, it still goes to a profile page :-s

I'l check out the errata like you said, thanks :-)

 

again, if anyway can shed some light on this i'll be very grateful!

 

all i need is the normal user/add user/edit etc which happens automatically, yet if i type in user/nonaction it would take you to user/viewprofile/nonaction, with nonaction being the users name :-P so only go to the view profile thing if there isnt an existing action in the controller :-)

Link to comment
https://forums.phpfreaks.com/topic/213964-zf-routing-insanity/#findComment-1113737
Share on other sites

with nonaction being the users name :-P so only go to the view profile thing if there isnt an existing action in the controller :-)

 

If you want to direct to a method/action use:

 

 

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

 

 

If you want to specify an artist and thus use a pre-defined route use:

 

 

$this->url(array('artistname' => 'The Smiths'), 'artistprofile', true);

 

Link to comment
https://forums.phpfreaks.com/topic/213964-zf-routing-insanity/#findComment-1113785
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.