好吧,我必须从$_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