문제

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