dtz88967 2014-09-08 15:36
浏览 35
已采纳

Codeigniter路由:控制器功能和变量冲突

I'm trying to simplify this code to a fewer lines.

// Controller function routing
$route['news/popular'] = "news/popular";
$route['news/featured'] = "news/featured";
$route['news/latest'] = "news/latest";

$route['news/index/(:any)'] = "news/index/$1"; // points to a url slug of article
$route['news/(:any)'] = "news/index/$1"; // points to article without 'index' segment

To this:

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

Not working at all. Are there any other methods for this? or should I stick to the long code?

  • 写回答

2条回答 默认 最新

  • dton37910 2014-09-08 15:58
    关注

    No you can't do that way in codeigniter routes as how can codeigniter guess which function you want to use.

    What you can try to reduce your routes is categorize news in single function.Something like this :

       function get_news($news_type)
        {
           //check here which type of news is required and process accordingly.
        }
    

    In your route it goes like this

    $route['news/(:any)'] = 'news/get_news/$1';
    

    Hope this help you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch