在HMVC码点火器模块内部扩展控制器


extend controller inside HMVC Codeigniter module

如何在模块本身中扩展HMVC模块的控制器

class Backend extends Backend_Controller {
    public function __construct(){
        parent::__construct();
    }
}

假设以下典型的Codeigniter文件结构与HMVC相关:

/
/application
/application/modules
/application/modules/backen
/application/modules/backen/controllers
/application/modules/backen/controllers/Backend.php
/application/modules/backen/libraries
/application/modules/backen/libraries/Backend_Controller.php

在这个结构中得到错误"class not found"。工作以放入文件夹"/application/librarys/Backend_Controller.php"。

控制器必须在CodeIgniter中扩展CI_Controller。控制器不能扩展库,但它们可以像这样包含它们$this->load->library('backendLib');

如果您使用的是Wiredesignz HMVC扩展,则可以为此使用基本控制器。只需在核心目录中创建一个backend_controller类,并使其扩展MX_controller。现在,您可以使模块控制器扩展backend_controller。

最佳,

Bart

Hi-CI始终寻找以CI_Controller开头的核心类或以MY_开头的扩展类名,如MY_ControllerMY_Email等。如果您要调用的任何其他类与库不同,您可以在config.php中添加以下代码,以自动加载自定义类

/*
| -------------------------------------------------------------------------
| Native spl_autoload_register() - by Kenneth Vogt
| -------------------------------------------------------------------------
|
| Here is an updated version of Phil Sturgeon’s code:
|
| Thanks to Phil Sturgeon Kenneth Vogt and InsiteFX.
|
| NOTE:
| Requires PHP 5.3.+
| As of CI 3.0 Dev - The constant EXT has been removed modified
| to use '.php' now instead of EXT.
| should work for all version of CI and PHP 5.3
|
| Place at the bottom of your ./application/config/config.php file.
| -------------------------------------------------------------------------
*/
spl_autoload_register(function($class)
{
    if (strpos($class, 'CI_') !== 0)
    {
        if (file_exists($file = APPPATH . 'core/' . $class . '.php'))
        {
            include $file;
        }
        elseif (file_exists($file = APPPATH . 'libraries/' . $class . '.php'))
        {
            include $file;
        }
    }
}); 

来自这个fourm post线程的参考http://forum.codeigniter.com/thread-473-post-2679.html#pid2679

现在,您可以使用自定义控制器名称Backend_controller来扩展您的控制器,该类应该在应用程序库或核心目录下可用