Codeigniter根据URL参数加载参数以在默认控制器中进行索引

时间:2013-12-18 11:57:32

标签: php codeigniter routes

我想在控制器中加载一个变量,用户在URL中输入的值作为参数,例如:当用户输入mysite.com/city1时。

应加载默认控制器,并使用city1设置变量。我的索引函数在默认控制器(名为home)中为

function index($location = ""){
 $this->load->view('header');
 $this->load->view('home_view', $this->viewData);
 $this->load->view('footer');
 }

我尝试编辑routes.php的条件,但似乎无法正常工作。我可以通过mysite.com/home/index/city1访问索引 但我想通过mysite.com/city1

访问它

2 个答案:

答案 0 :(得分:2)

$route['home/(:any)'] = "home/index/$1";

答案 1 :(得分:1)

uri课程处理你需要的东西!

$this->uri->segment(n);

见这里:http://ellislab.com/codeigniter/user-guide/libraries/uri.html

相关问题