0
我設置的提取以下獲取的參數了URI
- 控制器
- 行動
- 參數
級路由器{
private $uri;
private $controller;
private $method;
private $params;
public function __construct($uri) {
$this->uri = $uri;
$this->method = 'index';
$this->params = array();
}
public function map() {
$uri = explode('/', $this->uri);
if (empty($uri[0])) {
$c = new Config('app');
$this->controller = $c->default_controller;
} else {
if (!empty($uri[1]))
$this->method = $uri[1];
// how about the parameters??
}
}
一個簡單的路由器類}
這個簡單的$router->map()
可以給我正確的控制器,動作和此URI http://domain.com/users/edit/2
這是非常好的一個參數,但如果我需要存儲在URL這樣的多個參數: http://domain.com/controller/action/param/param2/param3
如果我不知道將傳遞多少個參數,我如何將它們推送到$parms
。
您在知道'$ uri [0]'是否爲空之前轉移了嗎?那會好嗎? –
您可以檢查$ uri [0]是否爲空,然後運行您的默認控制器代碼。這是你的框架,我會把這個決定留給你。 –