我有一个网址www.mywebsite.com/store/123456
其中 store 是我的 Controller 类,其中有一个索引函数,我在 store 之后获取值,即 123456。但我无法实现它。
据网上发现,我尝试将其添加到路由$route['store/(:any)'] = 'store/index';
也尝试过
$route['store/(:any)'] = 'store/index/$1';
但似乎不起作用。请帮助我。
在 Controller 中索引函数是
public function index()
{
echo $this->uri->segment(1);
}
但它不起作用。请帮忙
最佳答案
您正在调用 123456()
方法而不是 index()
方法,因此您会得到 CI 的 404。
最简单的方法就是使用这种路由
$route['store/(:any)'] = 'store/index/$1';
并在其顶部添加参数到您案例中的索引函数
public function index($parameter)
{
echo $this->uri->segment(2);
}
请注意,我更改了段参数,请参阅 documentation 。
使用_remap()
function _remap($parameter){
$this->index($parameter);
}
function index($p)
{
echo $p; //shows 123456
}
关于php - 用于将 get 参数传递给索引函数的 Codeigniter 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27205194/