在 CodeIgniter 中找不到错误类控制器

2022-01-05 00:00:00 class php codeigniter controller

您好,我在 CodeIgniter 中遇到 Controller not found 错误.这是我的控制器代码

Hello, I am getting Controller not found error in CodeIgniter. This is my Controller code

<?php

class HelloWorld extends Controller
{

    function HelloWorld()
    {
        parent::Controller();
    }

    function index()
    {
        $this->load->view('index_view');
    }

    function hello()
    {
        $this->load->view('hello_view');
    }

}
?>

这是视图代码:

你好,很高兴见到你!

执行时出现此错误:

致命错误:在第 2 行的 D:wampwwwCodeIgniter_2.0.2applicationcontrollershelloworld.php 中找不到 Class 'Controller'

谁能告诉我为什么会出现这个错误?

Can anyone tell me why I get this error?

推荐答案

从 CodeIgniter 2.x 开始,CI_ 前缀被添加到所有核心类中.检查更改日志.

As of CodeIgniter 2.x CI_ prefix is added to all core classes. Check the Change Log.

为所有核心类添加了 CI_ 前缀.

对于 CodeIgniter 2.x

For 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

For 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');
    }

}

希望对你有帮助.谢谢!!

Hope this helps you. Thanks!!

相关文章