【问题标题】:Codeigniter - retrieve parameter without controller name in URLCodeigniter - 在 URL 中检索没有控制器名称的参数
【发布时间】:2014-07-23 23:41:53
【问题描述】:

我正在尝试使用以下 URL 方案检索字符串作为参数: www.myapp.com/[字符串]

有什么办法可以做到吗?

*根据我的研究,除非我在 URL 中包含控制器的名称,否则 Codeigniter 不接受字符串参数:www.myapp.com/[Controller Name]/[String] 但这并不能解决我的问题:(

【问题讨论】:

  • 你有什么问题。 ?

标签: codeigniter url uri codeigniter-url


【解决方案1】:

你说得对,CI 需要 URI 中的控制器名称,但你可以使用 default_controller。

config/routes.php添加路由规则$routes['(:any)'] = 'welcome/index';, remove index.php from Your URL (there're many tutorials and how-to for this), and at last useuriclass at Yourindex()method ofwelcome`控制器:

function index(){
    var_dump($this->uri->uri_string());
}

【讨论】:

  • 按照您的指示输入“myapp.com/[String]”后,我被重定向到 404。我认为它仍在寻找控制器(而不是获取参数)?跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-25
  • 1970-01-01
  • 2011-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-02
相关资源
最近更新 更多