2008年12月8日星期一

Re: [fw-mvc] Router_Route - Routing requests to another controller

Resolved: see update below.


jkendall wrote:
>
> I'm having trouble getting a route set up. I've got a modular MVC app up
> and running. Inside of my 'forms' module I have a controller with a
> fairly long name. The client would like to change what they're seeing in
> the URL, and I'd like to avoid refactoring the entire module.
>
> The original request would look something like:
>
> array(
> 'module' => 'forms',
> 'controller' => 'really-long-name',
> 'action' => 'index' // or whatever action that I'm requesting at
> the time
> );
>
> I've tried setting up a route like the one below:
>
> $route = new Zend_Controller_Router_Route(
> ':module/shorter-name/:action/*',
> array('controller' => 'really-long-name')
> );
> $router->addRoute('shorter-name', $route);
>
> When I try to use that route (http://example.com/mvc/forms/shorter-name),
> I get an "Invalid controller specified (shorter-name)" error.
>
> Is it possible to map routes in this manner?
>
>
>

Update: I was able to resolve the issue by providing the full path of the
route (duh), a value for the module key, and a default value for 'action'.
The working route looks like this:

$route = new Zend_Controller_Router_Route(
'forms/shorter-name/:action/*',
array(
'module' => 'forms',
'controller' => 'really-long-name',
'action' => 'index'
)
);

http://example.com/mvc/forms/shorter-name now works, as well as
http://example.com/mvc/forms/shorter-name/thanks and
http://example.com/mvc/forms/shorter-name/view/id/3


-----
Jeremy Kendall -- http://www.jeremykendall.net http://www.jeremykendall.net
--
View this message in context: http://www.nabble.com/Router_Route---Routing-requests-to-another-controller-tp20903100p20904294.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: