Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.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
Php CodeIgniter:库类未加载此代码_Php_Codeigniter - Fatal编程技术网

Php CodeIgniter:库类未加载此代码

Php CodeIgniter:库类未加载此代码,php,codeigniter,Php,Codeigniter,我是CodeIgniter新手,下面是一个Nettuts高级教程,介绍如何在CodeIgniter中构建CMS 首先,我的应用程序和系统目录位于public_html之外的不同路径上,并在config.php文件中设置路径 我已经创建了两个文件Frontend_Controller.php和Admin_Controller.php,在这些文件中创建了一个类,如下所示 应用程序/My_Controller.php class MY_Controller extends CI_Controller

我是CodeIgniter新手,下面是一个Nettuts高级教程,介绍如何在CodeIgniter中构建CMS

首先,我的应用程序系统目录位于public_html之外的不同路径上,并在config.php文件中设置路径

我已经创建了两个文件Frontend_Controller.php和Admin_Controller.php,在这些文件中创建了一个类,如下所示

应用程序/My_Controller.php

class MY_Controller extends CI_Controller
{

    public $data = array();

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

        $this->data['errors'] = array();
        $this->data['site_name'] = config_item('site_name');
    }
}
class Frontend_Controller extends MY_Controller
{

    function __construct()
    {
        parent::__construct();
    }
}
class Admin_Controller extends MY_Controller
{

    function __construct()
    {
        parent::__construct();
    }
}
库/Frontend_Controller.php

class MY_Controller extends CI_Controller
{

    public $data = array();

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

        $this->data['errors'] = array();
        $this->data['site_name'] = config_item('site_name');
    }
}
class Frontend_Controller extends MY_Controller
{

    function __construct()
    {
        parent::__construct();
    }
}
class Admin_Controller extends MY_Controller
{

    function __construct()
    {
        parent::__construct();
    }
}
库/Admin\u Controller.php

class MY_Controller extends CI_Controller
{

    public $data = array();

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

        $this->data['errors'] = array();
        $this->data['site_name'] = config_item('site_name');
    }
}
class Frontend_Controller extends MY_Controller
{

    function __construct()
    {
        parent::__construct();
    }
}
class Admin_Controller extends MY_Controller
{

    function __construct()
    {
        parent::__construct();
    }
}
现在,当我试图通过在config.php文件中写入一个_autoload()函数来自动加载上述类时,它不会加载文件/类

config.php

function __autoload($classname)
{
    if(strpos($classname, 'CI_' !== 0))
    {
        $file = APPPATH . 'libraries/' . $classname . '.php';

        if(file_exists($file) && is_file($file))
        {
            @include_once($file);
        }
    }
}

谁能帮我理解和解决这个问题。。。非常感谢

您可以在
application/config/autoload.php
文件中尝试使用codeigniter autoload 像这样:

`$autoload['libraries'] = array('database', 'session');`
详情请参阅:

您也可以尝试使用此选项:

下面的代码段查看以下小写文件名位置:核心/库/模型/

function __autoload($class) 
{
  $path = array('core', 'libraries', 'models');

  if(strpos($class, 'CI_') !== 0) {
    foreach($path as $dir) {
      if (file_exists(APPPATH.$dir.'/'.strtolower($class).'.php'))
        include_once(APPPATH.$dir.'/'.strtolower($class).'.php');
    }
  }
}

为什么不使用CI的自动加载?为什么要在配置中加载类?哦!我对此不太了解。你能教我怎么做吗?你看过文档了吗?很好,我相信它会回答你的问题。作为个人建议,您应该在使用框架/库文档之前阅读它…是的,我已经阅读了文档,需要在autoload.php中定义,但是我仍然不知道如何编写类名以及在哪里编写?因为我在库中有控制器类,也有大写的文本。谢谢你的回答。。一个与此相关的问题。。当我使用
$autoload['libraries']
时,如何将
Frontend_Controller
写入阵列<代码>数组(“前端”)是这样吗?我想前端控制器不是一个库…你不会自动加载控制器!那是我自己的文件类。。请在我的问题中提及。。那么我如何加载这个类呢?CI可能很好,但理解起来非常混乱,至少对于像我这样的初学者来说是如此(请看这里也请看这里: