Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法使用路由从Codeigniter中的url中删除子文件夹目录_Php_Codeigniter_Codeigniter 2 - Fatal编程技术网

Php 无法使用路由从Codeigniter中的url中删除子文件夹目录

Php 无法使用路由从Codeigniter中的url中删除子文件夹目录,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,我在控制器中具有以下目录结构: Controllers |__ posts |__ post.php views |__ welcome_message.php |__ home.php 欢迎来到message.php 欢迎来到CodeIgniter home.php 欢迎来到CodeIgniter链接页面 这是链接页面 以{exposed\u time}秒呈现的页面 welcome.php 当我点击welcome_message.php中的链接时,我得到

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

Controllers
  |__ posts
      |__ post.php

views
  |__ welcome_message.php
  |__ home.php
欢迎来到message.php


欢迎来到CodeIgniter
home.php


欢迎来到CodeIgniter链接页面
这是链接页面

{exposed\u time}秒呈现的页面

welcome.php



当我点击welcome_message.php中的链接时,我得到以下url
http://localhost/url_routing/posts/post/posts_controller
但我想从url中删除帖子(即文件夹名),所以我尝试了
$route['posts']=“post/posts\u controller”
位于routes.php文件夹中,但结果相同。所以请帮我解决我的问题,如果可能的话给我一个小的解释,我从stackoverflow中看到了其他答案,但无法完全理解。

您的默认基本url是什么?@cos-nik:这是我的基本url:如果我是正确的,您希望在此url中看到主视图:localhost/url/routing/post/posts\u controller?我是指localhost/url\u routing/post\u controller?为什么在url中进行路由。这应该是url(posts是控制器中的文件夹名称)您的默认基本url是什么?@cos-nik:这是我的基本url:如果我是正确的,您希望在此url中查看主视图:localhost/url/routing/post/posts\u controller?我是指localhost/url\u routing/post/posts\u controller?为什么在url中进行路由。这应该是url(posts是控制器中的文件夹名称)
$route['post/posts_controller'] = 'posts/post/posts_controller';
<!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 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

Class Post extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
    }

    public function posts_controller()
    {
        $this->load->view('home');
    }

}
?>
$route['post/posts_controller'] = 'posts/post/posts_controller';