2009年3月2日星期一

[fw-mvc] Re: [fw-general] Re: Using custom router. Where exactly?

-- vadim gavrilov <vadimg88@gmail.com> wrote
(on Monday, 02 March 2009, 03:15 PM +0200):
> Any example for this? Since i saw that Matthew didn't use any router.

The router is used on every request -- I simply wasn't defining any
custom *routes* -- and herein lies your confusion, I think.

Zend_Controller_Router_Regex is registered with the front controller by
default. This router, by default, registers a route that corresponds to
(:module/):controller/:action/*. I you want any additional routes, you
must register them yourself -- and you must do so *before* the router is
invoked.

Router invocation is the first part of the front controller's dispatch()
routine. You have two places you can then register routes: your
bootstrap, or in a routeStartup() plugin.

The current stable pastebin app uses an "Initialize" plugin that is
registered with routeStartup(), and could be easily modified to do route
initialization if necessary.

On the whole, however, it's rare that you will need to do explicit,
custom routes per controller; if you are, you may want to re-think your
routing strategy to make it more predictable and uniform.

As for custom routes per module, you have several options.

* In your bootstrap, loop through each module directory and check for
a route bootstrap (a similar tack is taken in the upcoming
Zend_Application), configuration file, and/or plugin.

* Use a config file to define routes for your entire application.

* Use a routeStartup() plugin that checks each module directory for a
configuration file defining routes for that module.


> 2009/3/2 Pawe Chuchma a <pawel.chuchmala@gmail.com>
>
> On Mon, Mar 2, 2009 at 13:33, vadim gavrilov <vadimg88@gmail.com> wrote:
> > Thanks i already looked at those files. Still can i place an instance of
> the
> > addRoute inside a certain controller? or do i need to place it somewhere
> in
> > the bootstarp file? Basically what i would like to do is to make a file
> that
> > will hold all the routes for each module/controller. Did anyone made
> > something like that before?
>
> The best file is for me routes.ini. in config directory;-)
> The rest in bootstrap initRoutes.
>
> Regards,
> pch
>
> --
> Pawe Chuchma a
> pawel.chuchmala at gmail dot com
>
>
>
>
> --
> Vincent Gabriel.
> Lead Developer, Senior Support.
> Zend Certified Engineer.
>
>
>
>

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: