Php Codeigniter路由正则表达式
我有这个:Php Codeigniter路由正则表达式,php,regex,codeigniter,routes,Php,Regex,Codeigniter,Routes,我有这个: $route['^[a-zA-Z]{2}$'] = "state"; $route['^[a-zA-Z]{2}$/(:any)'] = "state/city"; 这些控制器呢 state.php class State extends CI_Controller { public function index () { echo "OK"; } public function city () { e
$route['^[a-zA-Z]{2}$'] = "state";
$route['^[a-zA-Z]{2}$/(:any)'] = "state/city";
这些控制器呢
state.php
class State extends CI_Controller {
public function index ()
{
echo "OK";
}
public function city ()
{
echo "Not OK";
}
}
第一条路线可以完美地工作,而第二条则不行。她应该调用城市的状态类方法,但不调用
网址:
-->OK-> 404!
删除锚定到字符串末尾的
$
:
$route['^[a-zA-Z]{2}/(:any)'] = "state/city";
删除锚定到字符串末尾的
$
:
$route['^[a-zA-Z]{2}/(:any)'] = "state/city";
您还需要用$1捕获通配符(:any)并将其传递给控制器/方法您还需要用$1捕获通配符(:any)并将其传递给控制器/方法