无法使用路由从代码点火器中的 url 中删除子文件夹目录


Cannot able to remove the subfolder directory from url in Codeigniter using routing

我在控制器中有以下目录结构:

Controllers
  |__ posts
      |__ post.php
views
  |__ welcome_message.php
  |__ home.php

welcome_message.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>
</head>
<body>
  <a href="<?php echo site_url("posts/post/posts_controller"); ?>">link</a>
</body>
</html>

首页.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter Link Page</title>
</head>
<body>
<div id="container">
    <h1>This is the link page</h1>
<div id="body">
    <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
</div>
</body>
</html>

欢迎.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
       public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
    }
    public function index()
    {
        $this->load->view('welcome_message');
    }
}

后.php

<?php
Class Post extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
    }
    public function posts_controller()
    {
        $this->load->view('home');
    }
}
?>

当我单击welcome_message.php中的链接时,我得到以下 URL http://localhost/url_routing/posts/post/posts_controller但我想从 URL 中删除帖子(即文件夹名称),所以我尝试在 routes.php 文件夹中$route['posts'] = "post/posts_controller";,但结果是一样的。所以请帮我解决我的问题,如果可能的话,给我一个小解释,我已经从stackoverflow看到了其他人的答案,但不能完全理解。

$route['post/posts_controller'] = 'posts/post/posts_controller';