url路由在CodeIgniter中不起作用

url路由在CodeIgniter中不起作用,codeigniter,Codeigniter,我想在CodeIgniter中使用路由,我无法获得,我想通过测试控制器这是代码 我想要像下面这样的url localhost/code/test,但我没有找到对象 routes.php $route['test'] = "test/blog"; test.php controller <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Te

我想在CodeIgniter中使用路由,我无法获得,我想通过测试控制器这是代码 我想要像下面这样的url localhost/code/test,但我没有找到对象

routes.php

    $route['test'] = "test/blog"; 

    test.php controller

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Test extends CI_Controller {

        /**
         * Index Page for this controller.
         *
         * Maps to the following URL
         *      http://example.com/index.php/welcome
         *  - or -  
         *      http://example.com/index.php/welcome/index
         *  - or -
         * Since this controller is set as the default controller in 
         * config/routes.php, it's displayed at http://example.com/
         *
         * So any other public methods not prefixed with an underscore will
         * map to /index.php/welcome/<method_name>
         * @see http://codeigniter.com/user_guide/general/urls.html
         */
        public function index()
        {
            $this->load->view('welcome_message');
        }

        public function blog()
        {

         echo "hi";
        }
    }

    /* End of file welcome.php */
    /* Location: ./application/controllers/welcome.php */
routes.php
$route['test']=“测试/博客”;
test.php控制器

您需要做的是在
views
文件夹中准备一个视图页面,如
blog.php
,您需要做的是在其中传递数据,并在控制器中调用视图部分,如

test.php

public function blog()
{
    $data['my_post'] = "Hello Its my first blog"; //some sort of operations or else likewise
    $this->load->view('blog',$data);
}
<h1><?php echo $my_post;?></h1>
blog.php中

public function blog()
{
    $data['my_post'] = "Hello Its my first blog"; //some sort of operations or else likewise
    $this->load->view('blog',$data);
}
<h1><?php echo $my_post;?></h1>


首先,将默认控制器设置为您的文件。从Route.php

如果您没有在Route中设置默认控制器,那么首先在设置特定路由之后设置它,如下所示

$route['default_controller'] = "Test";
$route['404_override'] = '';
$route['test'] = 'test/blog';
$route['test/(:any)'] = 'test/blog/$1';