我有一个链接Example.com/Entertainment/Cinema/200
我想从基于Codeignitor Controller的链接中获取值
我的默认控制器是News
class News extends CI_Controller {
public function index($p1="",$p2="",$p3="")
{
echo $p1,$p2,$p3;
}
function _remap($p1,$p2,$p3){
$this->_index($p1,$p2,$p3);
}
我想这样访问它www.Example.com/Entertainment/Cinema/774/
但是我只能返回$p1怎么做呢?
可以使用URI Routing
试着用这个:
$route['news/(:any)/(:any)/(:any)'] = 'news/index';
现在你可以有一个这样的URL:
example.com/news/Entertainment/Cinema/774
查看更多信息。进入本页:
http://www.codeigniter.com/userguide3/general/routing.html但是你也可以不使用URI路由访问你的参数,就像这样设置你的URL:
example.com/news/index/Entertainment/Cinema/774
您只需要在控制器名称(类)和参数之间添加index
,以便CI知道您正在尝试访问控制器(新闻)中的索引方法。