我的本地主机中有一个名为blog.php的控制器。要访问它,我在地址栏中键入 http://localhost/ci/index.php/blog。在教程中,它说它将显示Hello World,但我得到的显示是一个包含博客.php代码和404页面未找到的页面。
这是代码。
*<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/blog
* - or -
* http://example.com/index.php/blog/index
* - or -
* So any other public methods not prefixed with an underscore will
* map to /index.php/blog/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
echo "Hello World";
}
}
/* End of file Blog.php */
/* Location: ./application/controllers/blog.php */*
任何人请帮助我知道问题所在。
您使用的是哪个版本的 CodeIgniter,因为CI_Controller适用于 CI 上的旧版本。你试过做吗
class Blog extends Controller {
}
或
class Blog extends MY_Controller {
}
在配置.php文件中设置MY_的位置。