質問

I've tried to create an app using routes but when I pass 2 parameters, nothing happens. The function is not fired.

When I use 1 param, it works:

$route['category_(:any)'] = 'category/categoryDetails/$1';
$route['category_(:any)/(:any)'] = 'category/categoryDemandeDetails/$1/$2';

and in my controller:

public function categoryDetails($name){
    $data = array('page' => 'category', 'categoryName' => $name);
    $this->load->view('category', $data);
}
public function categoryDemandeDetails($name, $demande){
    $data = array('page' => 'category',  'categoryName' => $name);
    $this->load->view('demande', $data);
}

Can you help me please?

役に立ちましたか?

解決

The first route will be catching all of the requests that start with category_, including any that should be routed to the second route. This is because (:any) will catch anything, including multiple parameters, so the second route would never be used in this order.

Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.

You just need to change the order of the routes:

$route['category_(:any)/(:any)'] = 'category/categoryDemandeDetails/$1/$2';
$route['category_(:any)'] = 'category/categoryDetails/$1';
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top