Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

building a PHP router [duplicate]

Possible Duplicate:
turn URL route into funciton arguments php mvc
CMS Routing in MVC

I'm currently trying to rewrite a PHP router.

The new htaccess rewrite has the follows.

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    public/    [L]
    RewriteRule    (.*) public/index.php?url=$1    [L]
</IfModule>

Whilst in index.php in public, I am getting the URL using the $url = $_GET['url'];

What I need to do is to pass $url to the Router function:: route($url)

If a URL is passed as : /page/function/$params which would then translate as : index.php?url=page/xapp/function, I'd need to map and route to Controller xapp and call function($params).

By this time, the autoloader has already been called. I'd also need to set a default function to be called if only /page/ is called.

How would I achieve this in a router?

like image 541
bear Avatar asked Nov 17 '12 15:11

bear


1 Answers

You should check out the code of klein.php, a small php router. I think you should figure it from that solution.

If not, check out also slim here

like image 80
tonino.j Avatar answered Oct 22 '22 02:10

tonino.j