你好,我在 CodeIgniter 中收到 Controller
not found 错误。这是我的 Controller 代码
<?php
class HelloWorld extends Controller
{
function HelloWorld()
{
parent::Controller();
}
function index()
{
$this->load->view('index_view');
}
function hello()
{
$this->load->view('hello_view');
}
}
?>
这是 View 代码:
你好,很高兴见到你!
我在执行时出现了这个错误:
fatal error :在第 2 行的 D:\wamp\www\CodeIgniter_2.0.2\application\controllers\helloworld.php 中找不到类“Controller”
谁能告诉我为什么会出现此错误?
最佳答案
从 CodeIgniter 2.x 开始,所有核心类都添加了 CI_
前缀。检查Change Log .
为所有核心类添加了 CI_ 前缀。
对于 CodeIgniter 2.x
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class HelloWorld extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('index_view');
}
function hello()
{
$this->load->view('hello_view');
}
}
对于 CodeIgniter 1.x
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class HelloWorld extends Controller
{
function HelloWorld()
{
parent::Controller();
}
function index()
{
$this->load->view('index_view');
}
function hello()
{
$this->load->view('hello_view');
}
}
希望对您有所帮助。谢谢!!
关于php - 在 CodeIgniter 中找不到错误类 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6492544/