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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.