2009年10月9日星期五

Re: [fw-mvc] Zend Controller Router with DB Lookup

What I did was combine two acts:  Building the site's dynamic navigation menus at the same time as determining where to adjust the program's flow.

Since I had to hit that database anyway to build the site's menus, I built a Pre-Dispatch Front Controller Plugin to do it, and from within that plugin calls an easily customizable class that interprets and acts upon any routes that need to be manually manipulated.  

At this point, the action stack only contains the Request that the Router has built.  If that Request needs to be replaced, it's easy.  If it needs to have another Request appended to the Stack, that's easy too.  This way I can have a single module to handle normal page/article delivery, but if that specific URL requires a calendar be added to the page, it can just be added to the stack, thus added to the content block following the article.

Tim Stiles




On Oct 9, 2009, at 9:57 AM, Eris Ristemena wrote:

Hi all,

Please could somebody tell me again why creating a router with database look up is a bad idea. Cause i find a case where i need my router to look into database to determine the correct module, controller and action for the request.

Let's say i have an article module, and i want these urls to map to a certain entry of my article table:

http://www.example.com/about-us  => Article_ArticleController::indexAction (alias='about-us')
http://www.example.com/featured-products  => Article_ArticleController::indexAction (alias='featured-products')
http://www.example.com/contact-us  => Article_ArticleController::indexAction (alias='contact-us')

but i also want these urls to map into my news module, forum module and gallery module respectively:

http://www.example.com/news  => News_NewsController::indexAction
http://www.example.com/forum  => Forum_ForumController::indexAction
http://www.example.com/gallery  => Gallery_GalleryController::indexAction


how can we determine this without having to check in to database, and see whether the path (alias) exists in article table or not?


regards,
eris

没有评论: