我无法使用codeigniter从url获取ID

我无法使用codeigniter从url获取ID,codeigniter,Codeigniter,我正在努力开发一个博客网站。我的问题是:我无法从url获取id 使用我的htaccess(我删除了index.php),这是我当前的链接: 以下是控制器的功能: public function post_look_up() { $id = $this->uri->segment(3); echo $id; } 以下是我的路线: $route['posts/(:any)']='blog/post_look_up'; 由于您已经重写了控制器/方法,因此希望使用URI类

我正在努力开发一个博客网站。我的问题是:我无法从url获取id

使用我的htaccess(我删除了index.php),这是我当前的链接:

以下是控制器的功能:

public function post_look_up() {
    $id = $this->uri->segment(3);
    echo $id;
}
以下是我的路线:

$route['posts/(:any)']='blog/post_look_up';

由于您已经重写了
控制器/方法
,因此希望使用URI类“
rsegment()
方法

$id = $this->uri->rsegment(3);

您可以看到,新设置的管线只有2个管段。
.

如果采用此约定,则必须标识字符串中的最后一个数字

$segment = $this->uri->segment(2); //or  3
$post_id = preg_replace('(\d+)$', '', $segment);

但我不会走这条路。我将仅基于slug加载帖子,仅使用$this->uri->segment(2)从db获取帖子。

到底出了什么问题?也许你可以详细说明一下手头的具体问题是什么,以及到目前为止你是如何解决的。id应该存储在url中的$id中,但它没有,因此当我回显$id时,我看不到任何回显。我知道函数post_look_up()是有效的,因为当我包含$this->load->view('header_view');对于函数,我看到了我的标题。
$segment = $this->uri->segment(2); //or  3
$post_id = preg_replace('(\d+)$', '', $segment);