我在我的codeigniter版本(2.2.0)应用程序中使用URI重新路由很困难。
这是我的routes.php
$route['details/(:num)'] = 'agent/manage_agents/$1';
在我的视图文件中
foreach($data as $value) {?>
<a href="<?php base_url();?>details/<?php echo $value['id']; ?>" class="btn btn-primary">Manage</a>
}?>
但我会得到404错误。
在我的Controller文件中
class Agent extends CI_Controller {
public function manage_agents($id)
{
echo $id;
}
}
更新
最后我找到了导致问题的原因。在我的routes.php中
$route['(:any)'] = "spotmyticket/$1";
隐藏此行时一切正常。 这是我的完整routes.php
$route['404_override'] = '';
$route['default_controller'] = "spotmyticket";
$route['ticket']="ticket";
$route['ticket/(:any)'] = $route['ticket'].'/$1';
$route['captcha'] = "captcha";
$route['captcha/(:any)'] = "captcha/$1";
$route['admin'] = "admin";
$route['admin/(:any)'] = "admin/$1";
$route['userdashboard'] = "userdashboard";
$route['userdashboard/(:any)'] = "userdashboard/$1";
$route['fbci'] = "fbci";
$route['fbci/(:any)'] = "fbci/$1";
$route['(:any)'] = "spotmyticket/$1";
$route['agent-management'] = 'agent/index';
$route['register'] = "agent/agent_register";
$route['test'] = 'agent/test';
$route['details/(:any)'] = 'agent/manage_agents/$1';
此处spotmyticket
是我网站的默认控制器
答案 0 :(得分:1)
将此行放在文件末尾。 $ route [&#39;(:any)&#39;]它打破了其他路由规则的执行。
$route['(:any)'] = "spotmyticket/$1";