ZF-5659: Router assemble() and default routes before dispatch


Hi, I noticed if you want to call assemble() before the FC dispatches the request, the default route is not present. I notice that the router initializes its default routes line 310 of the route() method on the rewrite router. Would it make more sense to have the default route initialized when the router is instantiated so that I may assemble() URLs during the bootstrapping process if I want to? I for one am going to sub-class my router and fix this, just figured there would be no down side to including this fix in upcoming releases, would there?


We do not register the default route when the router is initialized for several reasons. First, some developers choose not to use the default route, and this would add overhead. Second, some developers register their own default route -- again, having the ZF implementation instantiated would add overhead. Finally, it's entirely possible that a routeStartup() plugin would register additional routes -- meaning that calling assemble() from the bootstrap may or may not work if the routes have not yet been registered.

Won't fix.

I understand what you're saying and that's a good point, but what about registering the default route if the programmer calls assemble() , if no route is found it could try to register the default route and try to fly with that, before throwing an exception? Then there is no performance overhead. The use case for this is that someone could want to instantiate a "navigation" model in a controller plugin or directly in the bootstrap, what would your proposed alternative be, other then sub classing the router for this workaround? subclass the action controller and instantiate the model there instead?

I would instantiate such a model in a dispatchLoopStartup() plugin - which ensures that the router has already fired (and hence all routes are defined). From there, you can pull the router from the front controller, and pass it to your model.

Sounds good, thanks for the comments