building a PHP router [duplicate]

依然范特西╮ 提交于 2019-12-04 13:40:35

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/13432016/building-a-php-router

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!