【问题标题】:Can't auto load the files in core directory无法自动加载核心目录中的文件
【发布时间】:2014-05-21 13:37:10
【问题描述】:

我不知道我做错了什么。在我的应用程序的核心目录中,我有两个文件 CMController.php 和 CMBase.php。

CMBase.php

class CMBase extends CI_Controller {}

CMController.php

CMController extends CMBase {}

然后在随机控制器中

class RandomController extends CMController {}

我明白了

Fatal error: Class 'CMBase' not found

配置中的子类前缀设置为 CM。 如果我在 CMController 文件中做 require_once 'CMBase.php' 它工作正常。 所以我的问题是为什么没有自动加载文件CMBase?

【问题讨论】:

    标签: php codeigniter class autoload


    【解决方案1】:

    当您扩展核心控制器时,您的类名需要以“Controller”结尾。所以你不能将你的班级命名为CMBase,它必须是CMBase_Controller

    所以如果$config['subclass_prefix'] 中的值是“CM”,那么你的类需要看起来像

    class CMController extends CI_Controller {//...}
    

    一旦你做到了,你就可以做到

    class AnyClassName extends CMController {//...}
    

    【讨论】:

      【解决方案2】:

      您是否尝试过查看 $config['subclass_prefix'] = 'MY_';应用程序文件夹。只能扩展MY_Controller等http://ellislab.com/codeigniter/user-guide/general/controllers.html

      https://github.com/EllisLab/CodeIgniter/wiki/MY-Controller

      我认为您缺少 _ 下划线部分,即 MY_

      【讨论】:

      • class CMBase extends CI_Controller {} try class "Your name" extends CMBase {} in core files 查看 hmvc 的加载方式 class MY_Loader extends MX_Loader {}
      猜你喜欢
      • 2013-02-16
      • 1970-01-01
      • 2011-01-05
      • 2018-02-25
      • 2021-02-12
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多