【问题标题】:Url shortener in codeignitercodeigniter 中的 URL 缩短器
【发布时间】:2019-12-13 16:29:04
【问题描述】:

我想缩短我的网址

我该如何改变这个:

http://qc-web.local.com/mydata/mydata_view?datemin=2017-03-11&datemax=2017-05-22

到此:

http://qc-web.local.com/mydata/mydata_view/2017-03-11/2017-05-22

【问题讨论】:

标签: php codeigniter


【解决方案1】:

在路由文件中试试这段代码

$route['mydata/mydata_view/(:any)/(:any)'] = 'Mycontroller/index';

在控制器中添加此代码

public function index($min_date, $max_date)
{
    var_dump($min_date);
    var_dump($max_date);
}

【讨论】:

    【解决方案2】:

    您可以在config/routes.php 中定义route,如下所示:

    $route['mydata/mydata_view/(:any)/(:any)'] = 'controller/method/$1/$2';
    
    // make sure to replace `controller` with your controller class name
    // and `method` with your Controller's method name.
    

    然后在控制器的方法中:

    public function method($date_min, $date_max)
    {
        var_dump($date_min);
        var_dump($date_max);
    }
    
    // `method` should match with method defined in the `routes.php` file.
    

    你可以阅读更多关于URI Routing here

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多