好吧,我必須從$_SERVER['REQUEST_URI']
從url獲取控制器和方法?
一個網址讓說,它給我們一個網址
http://localhost/controller/method
我已經試過類似
explode('/',$_SERVER['REQUEST_URI'])
,它給了我們像
array
0 => string '' (length=0)
1 => string 'controller' (length=10)
2 => string 'method' (length=6)
獲得控制器或方法的最佳方式是什麼?或刪除數組中的0? (第一陣列)?
所以它會像
$controller = 'controller';
$method = 'method';
從上方投入。 也許關於名單?仍然沒有線索使用列表()。
編輯繼承人什麼香港專業教育學院迄今所做
$this->url = str_replace(config('foldertoscript'), NULL, $_SERVER['REQUEST_URI']);
$hello = explode('/',$this->url);var_dump($hello);
array_shift($hello);
list($controller,$method) = $hello;
var_dump($hello,$controller);
一類
感謝拜訪。
亞當·拉馬丹
$ _SERVER ['REQUEST_URI']在您包含控制器/方法的情況下不包含主機名。所以不用擔心。我相信你做錯了 – 2011-01-20 08:22:14
list()運算符就是爲了這個目的。 **然而,**我會使用不爆炸,但正則表達式一次作出**驗證**。 – 2011-01-20 08:37:20