dongzhent208577 2014-01-25 14:38
浏览 45

如何将值/变量直接传递给codeigniter中的默认控制器?

Assume base_url is "http://www.facebook.com"

Default controller is "Home"

How do i code my routes and controller to get my URL as "http://www.facebook.com/noddycha"

Where "noddycha" is a get parameter. The page should load my profile page from DB.

  • 写回答

1条回答 默认 最新

  • dongyangzhi0687 2014-01-25 15:24
    关注

    In your application/routes.php file add this line after $route['404_override'] = '';:

    $route['(:any)'] = 'users/profile';
    

    Now absolutely everything will be redirected the profile function of the users controller (or whichever controller/function combination you substituted in the routes.php file). Then you can get the parameter by doing this in the profile function:

    if ($this->uri->total_segments() === 1) {
        $profile = $this->uri->total_segment(1);
    }
    

    If you have some other controllers which you would still like to be able to access, e.g. an about us page, add them after the above line in the routes.php file. For example, if we extend the example above:

    $route['(:any)'] = 'users/profile';
    $route['home/about'] = 'home/about_us';
    

    Would mean that every request is sent to the users/profile function, except http://example.com/home/about will go to the about us page.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端