在路由中编写规则.php为 Codeigniter


Writing rules in routes.php for Codeigniter

我需要路线方面的帮助.php

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

对于那些我在路由中编写了 2 条规则.php具有与 - 相同的控制器 -

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

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

试试这个

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

链接是可以的,但路由映射的主要方面是您在设置中指定的控制器和函数名称。如果它们不存在,您将收到 404 错误。

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

//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
   }
   .....
}

在路由中.php对于 CodeIgniter,请遵循以下规则:

使用 $route 数组定义自定义路由。使用 URL 模式映射到特定的控制器和方法。使用占位符 {} 捕获和传递参数。为回退行为设置默认路由。使用 .htaccess 和配置设置从网址中删除索引.php。通过遵守这些规则,您可以在 CodeIgniter 中有效地配置和管理 URL 路由。