Thursday, 22 August 2013

How to write simple routes in PHP

How to write simple routes in PHP

I'm working on a project using Cloud9 IDE, running PHP5 on Apache 2.0. I'm
primarily a front-end developer, but I have decent experience with PHP.
I'm familiar with MVC frameworks, and to a lesser degree, this
functionality is what I'm trying to emulate, but simpler. I tried
implementing CakePHP, but found it was a little too robust for what I
needed -- I don't want a backend-heavy setup. I want to write some custom
sort of routing mechanism for my application.
Ideally, I would like every request to my site to come through one page
(this custom "Controller"), and from there I can write my own logic to
figure out the appropriate templates, http codes, errors, etc., to
include. My question is, how do I make this happen? In other words, how do
I make a request to http://mysite.c9.io/user/view/2 get channeled through
http://mysite.c9.io/index.php , and not try to request the /user/view/2
directory on my server?
I'm vaguely familiar with mod_rewrite and .htaccess rules, but I suspect
they may play a role here.

No comments:

Post a Comment