Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.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
Codeigniter,php5,致命错误:Class';控制器';找不到_Php_Codeigniter - Fatal编程技术网

Codeigniter,php5,致命错误:Class';控制器';找不到

Codeigniter,php5,致命错误:Class';控制器';找不到,php,codeigniter,Php,Codeigniter,致命错误:在第3行的\system\application\controllers\welcome.php中找不到类“Controller” <?php class Welcome extends Controller { function __construct() { parent::Controller(); } function index() { $this->load->view('

致命错误:在第3行的
\system\application\controllers\welcome.php中找不到类“Controller”

<?php

class Welcome extends Controller {

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

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

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

似乎您的Codeigniter位于与“/”不同的文件夹中。如果不在index.php或config.php中更改BASEPATH或系统根路径,将导致出现问题

检查index.php中的第14-26行(?)中的“系统”变量

/*
|---------------------------------------------------------------
| SYSTEM FOLDER NAME
|---------------------------------------------------------------
|
| This variable must contain the name of your "system" folder.
| Include the path if the folder is not in the same  directory
| as this file.
|
| NO TRAILING SLASH!
|
*/
    $system_folder = "system";

更改它以反映系统文件夹的路径,CI肯定会找到您的控制器类。

问题是我直接访问此文件(如“treeface”所述),但使用此路由生成找不到的页面

127.0.0.1:8000/test_ci/index.php/welcome

然后我安装了WAMP并使用

localhost/test\u ci/index.php/welcome

这是有效的!

很抱歉给您带来不便

不需要定义类的构造函数。这是codeigniter 2.0或更高版本框架的代码

class Welcome extends CI_Controller {

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

因为您使用的是旧版CodeIgniter的代码,所以请使用以下代码:

class Hello extends CI_Controller
{
    var $name;
    var $color;
    function Hello()
    {
        parent :: __construct();
        $this->name = "Name";
        $this->color = "red";
    }
    function you()
    {
        $data["name"] = $this->name;
        $data["color"] = $this->color;
        $this->load->view("you_view", $data);
    }

}

扩展CI_控制器而不是控制器
在切换到CI_控制器之前,我在代码点火器中遇到了相同的问题

您采取了哪些步骤来获取此代码?你确定你是通过index.php而不是直接访问这个文件吗?@rabidmachine关闭php标记是可选的,有时它会有帮助。检查一下这个,我不认为这是正确的problem@treeface似乎这就是问题所在,我是直接访问此文件的,但使用此路径生成的页面未找到?我现在正在安装WAMP,猜测我的路由中的问题!