CodeIgniter-使用slug从url隐藏函数名称

时间:2017-10-11 14:32:11

标签: php codeigniter routes

我有一个控制器Leads&有两个功能

  1. 索引
  2. 铅细节
  3. 这是我的代码

    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

    不重复

    问题在于索引功能。我怎么能用application / config / routes.php做到这一点?

    示例:leads / index指向错误,因为它指向lead_details函数

1 个答案:

答案 0 :(得分:0)

如下所示:

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

leads作为第一段的网址,第二段中的任何内容都会重新映射到leads类/控制器和lead_details方法/功能。

如果输入:

  • yoursite.com/leadsyoursite.com/leads/index,它将路由到index类的leads函数。
  • yoursite.com/leads/nice-not-to-have-2leads/lead_details

CI_VERSION : '3.0-dev'

上进行了测试
相关问题