da1lbi3 da1lbi3 - 9 days ago 6
PHP Question

Load controller from module hmvc codeigniter

I have my normal mvc directory's at codeigniter like:


  • Models

  • Views

  • Controllers



But I use the wiredesigz "plugin" for hmvc support, so I have this structure:


  • Models

  • Views

  • Controllers

  • Modules


    • TestModule


      • Models

      • Views

      • Controllers





I have this code at my root controllers folder:

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

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


And this at the /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);
}
}


But I get the error that class Core_Test_Controller is not found. Why can't I acces that controller from another controller? Is this even possible?

Fixed it:

Modules::load('../Core_Test_Controller/')->getText();

Answer

First off lower case for folder names. Only first letter must be upper case for controller names and models etc UCFIRST as explained here http://www.codeigniter.com/user_guide/general/styleguide.html#file-naming HMVC wont pick up CI_Controllers controllers only MX_Controllers

class Core_test_controller extends MX_controller {...}

class Insertcontroller extends MX_Controller {...}

As said here

<?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. **/