从模块hmvc codeigniter

时间:2016-11-30 19:41:56

标签: php codeigniter hmvc

我在codeigniter上有正常的mvc目录,如:

  • 模型
  • 观看次数
  • 控制器

但我使用wiredesigz“插件”来支持hmvc,所以我有这个结构:

  • 模型
  • 观看次数
  • 控制器
  • 模块
    • TestModule
      • 模型
      • 浏览
      • 控制器

我在根控制器文件夹中有这个代码:

class Core_Test_Controller extends MX_controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getText() {
        return "hi";
    }
}

这是在/ Modules / TestModule / Controllers:

   class InsertController extends MX_Controller
    {
        public function __construct(){
            parent::__construct();
        }

       function testIt{
           $coreTestController = new $this->Core_Test_Controller();
           $text = $coreTestController->getText();
           print_r($text);
        }
    }

但是我得到了找不到类Core_Test_Controller的错误。为什么我不能从另一个控制器访问该控制器?这甚至可能吗?

修正了它:

模块::负载( '.​​./ Core_Test_Controller /') - >的getText();

1 个答案:

答案 0 :(得分:1)

首先关闭文件夹名称的小写字母。对于控制器名称和模型等,只有第一个字母必须是大写字母,如此处所述的UCFIRST http://www.codeigniter.com/user_guide/general/styleguide.html#file-naming HMVC不会只接收CI_Controllers控制器MX_Controllers

class Core_test_controller extends MX_controller {...}

class Insertcontroller extends MX_Controller {...}

如上所述

<?php
/** module and controller names are different, you must include the method name also, including 'index' **/
modules::run('module/controller/method', $params, $...);

/** module and controller names are the same but the method is not 'index' **/
modules::run('module/method', $params, $...);

/** module and controller names are the same and the method is 'index' **/
modules::run('module', $params, $...);

/** Parameters are optional, You may pass any number of parameters. **/
相关问题