CodeIgniter-从带有slug的url中隐藏函数名

hgb9j2n6  于 2022-12-06  发布在  其他
关注(0)|答案(2)|浏览(110)

我有一个控制器引线,有两个功能
1.索引
1.引线细节
这是我的代码

class Leads extends CI_Controller {
  public function index(){}
  public function lead_details($slug){}

其工作原理如下

www.mysite.com/leads/    This will access to index function
www.mysite.com/leads/lead_details/nice-not-to-have-2

现在我想得到的细节

www.mysite.com/leads/nice-not-to-have-2

我试过了,但它与索引函数混淆

$route['leads/(:any)']  = 'leads/lead_details'

注意:这不是this的副本
问题是与索引功能。我怎么能做它与应用程序/配置/路由.php?
示例:leads/index给予lead_details函数时出错

g0czyy6m

g0czyy6m1#

纠正如下:

$route['leads/index']  = 'leads';
$route['leads(/:any)'] = 'leads/lead_details$1';

leads作为第一段的URL,第二段中的任何内容都将被重新Map到leads类/控制器和lead_details方法/函数。
如果您键入:

  • 无论是yoursite.com/leads还是yoursite.com/leads/index,它都将路由到leads类的index函数。
  • yoursite.com/leads/nice-not-to-have-2leads/lead_details
    CI_VERSION : '3.0-dev'上测试
aij0ehis

aij0ehis2#

如果你想路由你控制器函数,去config-〉routes.php,然后在这里解决你的路由,就像这样$route [′ routename ′] = ′ leads/leads-details ′;#url函数

相关问题