6

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?

Community
  • 1
  • 1
bear
  • 11,364
  • 26
  • 77
  • 129
  • or [Is this a good way to match URI to class/method in PHP for MVC](http://stackoverflow.com/questions/7033318/is-this-a-good-way-to-match-uri-to-class-method-in-php-for-mvc) – mario Nov 17 '12 at 15:45
  • You may try this router package too, https://github.com/miladrahimi/phprouter – Milad Rahimi Mar 23 '16 at 16:37

1 Answers1

9

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

tonino.j
  • 3,837
  • 28
  • 27