Uri重新路由codeigniter

时间:2015-12-23 15:40:03

标签: php html codeigniter

我在我的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"; when hide this line everything works  fine.

这是我的完整routes.php

$ route [&#39; 404_override&#39;] =&#39;&#39;;

$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';

2 个答案:

答案 0 :(得分:0)

如果你正在写这条路线:

$route['details/(:num)'] = 'agent/manage_agents/$1';

这样你就可以传递任何整数值(比如传递$ value ['id']),然后尝试使用(:any)而不是(:num)。所以你的路线应该是:

$route['details/(:any)'] = 'agent/manage_agents/$1';

答案 1 :(得分:0)

请将$route['(:any)'] = "spotmyticket/$1";定义为routes.php中的最后一条规则。一切都会好起来的。此规则适用于任何网址,因此将忽略此规则之后定义的所有规则。