构建一个 PHP 路由器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13432016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
building a PHP router
提问by bear
Possible Duplicate:
turn URL route into funciton arguments php mvc
CMS Routing in MVC
I'm currently trying to rewrite a PHP router.
我目前正在尝试重写一个 PHP 路由器。
The new htaccess rewrite has the follows.
新的 htaccess 重写如下。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/index.php?url= [L]
</IfModule>
Whilst in index.php in public, I am getting the URL using the $url = $_GET['url'];
在 index.php 中public,我使用$url = $_GET['url'];
What I need to do is to pass $urlto the Router function:: route($url)
我需要做的是传递$url给路由器功能::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 xappand call function($params).
如果 URL 作为 : /page/function/$params 传递,然后将转换为 : index.php?url=page/xapp/function,我需要映射并路由到 Controllerxapp并调用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.
此时,自动加载器已经被调用。如果仅调用 /page/ ,我还需要设置要调用的默认函数。
How would I achieve this in a router?
我将如何在路由器中实现这一点?

