在Codesigniter的routes.php中编写规则

时间:2016-02-16 11:03:57

标签: php codeigniter routes

我需要帮助routes.php

我有两种类型的网址,例如 - https://www.seekmi.com/service/jakarta/digital-marketinghttps://www.seekmi.com/en/service/jakarta/digital-marketing

对于那些我在routes.php中用相同的控制器写了2条规则 -

$route['en/service/(:any)/(:any)'] = "findservice/search/$1/$2";
$route['service/(:any)/(:any)'] = "findservice/search/$1/$2";

但只有第一个URL有效,而不是第二个。 你们中的任何人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

试试这个

$route['service/(:any)/(:any)'] = "findservice/search/$1/$2";
$route['en/service/(:any)/(:any)'] = "findservice/search/$1/$2";

答案 1 :(得分:0)

链接没问题,但路线映射的主要方面是您在设置中指定的控制器和功能名称。如果它们不存在,您将收到404错误。

因此,您需要在控制器中创建一个findservice Controller和一个方法搜索,以接受两个参数。

//save as findservice.php in application/controller/ folder

class Findservice extends CI_Controller{
   public function __construct(){
      parent::__construct();
   }
   public function search($param1,$param2){
      //use $param1 and $param2
   }
   .....
}