Page 1 of 1
Zend Framework's Rewrite Router
Posted: Thu Feb 15, 2007 4:18 pm
by Luke
I've got the following route set up...
Code: Select all
$routes['rotary_calendar'] = new Zend_Controller_Router_Route(
'calendar/:year/:month',
array('controller' => 'event', 'action' => 'calendar', 'year' => $date['year'], 'month' => $date['mon']),
array('year' => '/d+', 'month' => '/d+')
);
Now this works fine if you enter in
http://www.site.com/calendar (it calls the correct controller, action and sets the default params), but if you try and enter parameters manually such as /calendar/2008/4, it tries to call "calendar" as a controller. This is not what I want... I want it to find this route and call event as the controller and calendar as the action, and then set 2008 as year and 4 as month. Does anybody know what I'm doing wrong?
Posted: Tue Feb 20, 2007 3:05 am
by CoderGoblin
First off, don't know the answer and I think you are probably more familiar with this than I am but ...
1) What happens though if you take array the validation array?
2) What happens f you try with just a single parameter ?
Posted: Tue Feb 20, 2007 9:58 am
by Jenk
It must be tripping onto the final route ('/:controller/:action') if it is calling calendar as the controller.
Try adding a var_dump or echo into the router source to see what it trips on.
Posted: Thu Feb 22, 2007 1:29 pm
by Luke
Code: Select all
[_requestUri:protected] => /Rotary/calendar/2007/3
[_baseUrl:protected] => /Rotary
[_basePath:protected] =>
[_pathInfo:protected] => /calendar/2007/3
[_params:protected] => Array
(
[controller] => calendar
[action] => 2007
[3] =>
)
[_aliases:protected] => Array
(
)
[_dispatched:protected] => 1
[_controllerKey:protected] => controller
[_actionKey:protected] => action
is that what you mean? That doesn't really tell me anything more than you did though (that it's using the last route). Hmm...
Posted: Thu Feb 22, 2007 1:52 pm
by Luke

I could have sworn I tried this before, but I changed it to this and now it works.
Code: Select all
$routes['rotary_calendar'] = new Zend_Controller_Router_Route(
'calendar/:year/:month',
array('year' => $date['year'], 'month' => $date['mon'], 'controller' => 'event', 'action' => 'calendar'),
array('year' => '[0-9]{2,4}', 'month' => '[0-9]{1,2}')
);
Posted: Thu Feb 22, 2007 3:25 pm
by xinnex
Sorry if I'm hijacking a thread here, but you seem to have cracked these router-things..
Have you tapped into the module-functionality with routers yet?
I'm trying to route
http://mysite.com/forum to a module called "SimpleForum".. ;
Code: Select all
/application
/default
/SimpleForum
/controllers
/views
etc.
Posted: Thu Feb 22, 2007 3:32 pm
by Luke
module-functionality?
never heard of it, but I just briefly noticed it in the manual. Maybe something like:
Code: Select all
$router->addRoute(
'forum',
new Zend_Controller_Router_Route('forum/:controller/:action', array('module' => 'SimpleForum', 'controller' => 'index', 'action' => 'index')
);
Posted: Thu Feb 22, 2007 3:35 pm
by xinnex
Thanks, I'll give it a shot..
(btw.. I'm talking about modules as in mvc-packages.. It's on in the list you posted about ZF 0.8.0)
Edit: For others struggling with modules and routers, I just realized that the manual has been updated, so much for bleeding edge...
http://framework.zend.com/manual/en/zen ... riterouter
Posted: Thu Feb 22, 2007 7:55 pm
by Jenk
Just noticed..
Code: Select all
array('year' => '/d+', 'month' => '/d+')
should be:
Code: Select all
array('year' => '\d+', 'month' => '\d+')
