简体   繁体   中英

Writing rules in routes.php for Codeigniter

I need a help for routes.php

I have 2 types of URLs like - https://www.seekmi.com/service/jakarta/digital-marketing and https://www.seekmi.com/en/service/jakarta/digital-marketing

and for those i wrote 2 rules in routes.php with same controller as -

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

but only first URL works, not second one. Can any one of you please help me resolve this issue ?

try this

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

The links are okay but the main aspect of the route mapping is the Controller and function name you specified in the setting. If they do not exist you will get 404 error.

So you need to create a findservice Controller and a method search in the controller to accept two parameters.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM