Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why would you want to use any PHP router instead of writing the rewrite rules within an Apache VirtualHost file or a .htaccess file?


Separation of concerns? Why would I ever want to implement business logic in an http server configuration file?


Umm.. what do you think a server is for?


The http server's job is to translate URLs into http requests for consumption by the application. The http server should generally be agnostic regarding the semantic meaning of your URLs, which take the form of business rules, the proper place for which is the application layer (whenever possible).


At a guess because you don't use apache, you don't have .htaccess / conf permissions, you are going to distribute your script and can't rely on the above, your router uses database or other external sources, you want to be like the cool kids, or because you want to, it works, and why not?


Let's say you are using Apache (so maybe that already means you're not one of the cool kids?), then why would you use any of the available PHP routers?

Overall, I'm not trying to discount anyone's work with developing PHP routers, but I'd like to understand the benefits of using them.


It would help decouple your application code and structure from Apache configuration and the need to be familiar with Apache configuration syntax and nuance. Your Apache config would just need to route all requests to your app root to one routing file, which is pretty simple, and then the routing file can process from there. You'd also have the benefits of more configurable routing, if you needed that (e.g. routing based on specific parameters in a POST instead of just based on the request url and method).


I would prefer to have all my behavior be in my codebase.

Also, restarting Apache after adding a route would get tedious during development.


I guess you are asking why not just use the filesystem one-one like mapping url to file?

A benefit of routing is that you can have a single point of contact in your app: a front controller. And you can place your route config in one place.

This router also has RESTful routing, detecting HTTP methods upfront that correspond to a predictable method name in a named class.


Do you have experience with massive http conf files? They become very hard to maintain! There is always going to be tradeoffs between maintainability, speed and ease of use. It just depends what sort of application you are running.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: