CodeIgniter-使用$route[';(:any)';]=';页面/视图/$1';如何使用其他控制器?

CodeIgniter-使用$route[';(:any)';]=';页面/视图/$1';如何使用其他控制器?,codeigniter,routing,controllers,Codeigniter,Routing,Controllers,使用时 $route['(:any)]='pages/view/$1' 我想在路由中使用其他控制器,例如: $route['del/(:any)'] = 'crud/del'; 这行不通。我想它会用的 pages/view/del/$1 删除项目时,不是我的crud控制器。如何解决此问题?如图所示,$route['(:any)]将匹配任何URL,因此请将其他自定义路由放在“全面覆盖”路由之前: 它百分之百地工作 $route['(:any)'] url is placed last in yo

使用时

$route['(:any)]='pages/view/$1'

我想在路由中使用其他控制器,例如:

$route['del/(:any)'] = 'crud/del';
这行不通。我想它会用的

pages/view/del/$1


删除项目时,不是我的crud控制器。如何解决此问题?

如图所示,
$route['(:any)]
将匹配任何URL,因此请将其他自定义路由放在“全面覆盖”路由之前:


它百分之百地工作

$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";

我知道这是个老问题,但我找到了一个很好的解决办法

默认情况下,CodeIgniter将优先权赋予routes config中的URL(即使指定了straight controller、method等),因此我将此优先级颠倒为:

system/core/Router.php
find
\u parse\u routes
方法中

在文字路由匹配下添加此代码:

$cont_segments = $this->_validate_request($this->uri->segments);
if ($cont_segments == $this->uri->segments) {
  return $this->_set_request($cont_segments);
}
我同意,这种方法有点错误,因为我们从system/core编辑文件,但我需要一个快速的解决方案来处理大量URL。

我可以使用$route['(:any)/(:any)]='(:any)/(:any)/index';
$cont_segments = $this->_validate_request($this->uri->segments);
if ($cont_segments == $this->uri->segments) {
  return $this->_set_request($cont_segments);
}