【问题标题】:Cannot read parameter $1 using CodeIgniter URI Routing无法使用 CodeIgniter URI 路由读取参数 $1
【发布时间】:2016-05-04 03:14:55
【问题描述】:

我有一个奇怪的问题。我的配置 CI 中有这样的 URI 路由:

$route['content/:num'] = "content/read/$1";

我也有控制器类“内容”和这样的“读取”方法:

class Content extends CI_Controller {
     public function read($id) {
         echo $id;
     }
 }

当我在浏览器 localhost/myweb/index.php/content/1 上输入这个 它总是回显“$1”而不是 1。

感谢您的热心帮助

【问题讨论】:

  • 试试 $route['content/(:any)'] = "content/read/$1"; 并检查文件名是 Content.php 而不是 content.php

标签: codeigniter routing uri


【解决方案1】:

在您的路线中,您错过了 :num 周围的括号

$route['content/(:num)'] = "content/read/$1";

【讨论】:

  • 天啊!我没有注意到。它现在工作。非常感谢
猜你喜欢
  • 1970-01-01
  • 2021-11-30
  • 1970-01-01
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-06
相关资源
最近更新 更多