CodeIgniter - When using $route['(:any)'] = 'pages/view/$1' how to use other controllers?

十年热恋 提交于 2019-11-28 14:16:30

As indicated, $route['(:any)'] will match any URL, so place your other custom routes before the "catch-all" route:

$route['del/(:any)'] = 'crud/del';
// Other routes as needed...
$route['(:any)'] = 'pages/view/$1';
Umair

Its hundred percent working

$route['(:any)'] url is placed last in your routes file

$route['(:any)/company_product_deal_detail']    =   "mypage_product_picture/deal_detail/$1";
$route['(:any)/company_service_deals/(:any)']    =   "mypage_service_deal_list/index/$1";
$route['(:any)/company_service_deals']    =   "mypage_service_deal_list/index/$1";

$route['(:any)']    =   "company/index/$1";

I know that it's an old question, but I have found myself a nice solution.

By default, CodeIgniter gives priority to URL's from routes config (even if straight controller, method etc. specified), so I have reversed this priority this way:

In system/core/Router.php find _parse_routes method.

Add this code under literal route match:

$cont_segments = $this->_validate_request($this->uri->segments);
if ($cont_segments == $this->uri->segments) {
  return $this->_set_request($cont_segments);
}

I agree, that this approach is kinda wrong, because we edit file from system/core, but I needed a fast soluttion to work with a lot of URL's.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!