问题描述:

i have this testing code which am working with ..

i have a module called ms and and another one called test

the test controller code is :

<?php

class Test extends MX_Controller {

public function __construct()

{

parent::__construct();

$this->template->title($this->config->item('site_name','app'));

}

public function index()

{

$this->template->build('index');

}

}

and the code inside ms is :

<?php

//ms module

class Msrofi extends MX_Controller {

public function __construct()

{

parent::__construct();

$this->template->title($this->config->item('site_name','app'));

}

public function index()

{

$t = Modules::run('test/test/index');

var_dump($t);

$this->template->build('index_message');

}

}

the problem is that the build function inside test is trying to find the index view file inside the ms views folder not the test views folder ..

i checked the $this->_module and it gave me the ms module name ..

any one know how to fix that ??

网友答案:

Since the test module is being called in the context of the ms one, $this->template->build() is looking for a view file in the ms module. The same way you can load models and libraries cross-module, you would have to do this for your view path as well:

class Test extends MX_Controller {

    public function index()
    {
        // This path works only from the "test" module
        // $this->template->build('index');

        // This path works from any module
        $this->template->build('test/index');
    }
}

It's a little annoying maybe to have to explicitly call the module path in the module itself, but cross-module dependency defeat some of the goals of modularity in the first place.

A quick aside: Modules::run() output not returned, but directly echoed, so you can't assign it to a variable or print_r/var_dump it without using an output buffer:

ob_start();
Modules::run('test/test/index');
$t = ob_get_clean();
var_dump($t);
网友答案:

You can try to change the module.php the run method

The following example is I have to use the fix solution

  1. Open the third_party/MX/Modules.php
  2. Near 75 lines to find

    $buffer = ob_get_clean();

  3. Increase in its following

    if($output === NULL && $buffer === ''){ $output = CI::$APP->output->get_output(); }

At this time, it should be able to work properly...

相关阅读:
Top