Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of using multiples routers?

I am starting to build my web application progressively, adding routes and other routes to the router. The application is not a single page application, in the sense that it offers relatively independent features.

For example, if you had to build an application including a wiki, a dashboard (and settings), as well as a game using the wiki's data, should you use only one router with many routes? or should you split the application into small sub-applications with their own controllers?

In both cases, how to handle the problem of i18n? and loaded bootstrapped models (in case of a single router)?

like image 751
Edouard Avatar asked Aug 12 '11 21:08

Edouard


1 Answers

Originally, I'll say it depends on your application architecture/features and the scale of websites you are going to do...

Pros for a single routing file

  • Compliant to the rule: simpler is -always- better, so if you don't really needs multiple routing file, just don't.
  • Multiple files may lead to collision problems that could be a hell to resolve.
  • My personnal experience, after having myself worked on a homemade web app, I kept only one single file in the app's directory.

But what about multiple routing file?

You could however find a legitimate usage to multiple routing files if you have different plugins to handle content-types (wiki, dashboard, gallery...), and if they automatically implement routes (that won't change from a website to another).

In this case you could use small file specifically for each plugins that will be automatically merged to the app routing file (Note: as I previously mentionned, by doing this you could experience route collisions between files). In my homemade app, I'm using this solution to handle the backend (admin) panel, I "solved" the collision problem, by reserving the "/admin/" route for the backend then all plugin's routes get prefixed with it.

The PHP-Framework Symfony example

Don't take the following as a "you should do it like this" but you can look how it's done in Symfony here: http://www.symfony-project.org/book/1_2/09-Links-and-the-Routing-System

# default rules
homepage:
  url:   /
  param: { module: default, action: index }

default_symfony:
  url:   /symfony/:action/*
  param: { module: default }

default_index:
  url:   /:module
  param: { action: index }

default:
  url:   /:module/:action/*

I18n

Are you willing to translate urls ? If yes, remember me simpler-is-better statement. Do you really need it ? I'm aware that it may grant you some SEO boost, but I don't think it would be worth the squeeze. In this case, you could use 1 file per language, per app.

PS: what do you mean by "bootstrapped models (in case of a single router)?"

like image 179
Profet Avatar answered Oct 16 '22 18:10

Profet