简体   繁体   中英

Codeigniter HMVC controller doesn't print when called from another controller

I don't understand why I get return from my controllers but it wont print a simple var_dump .

Steps I follow:

  1. modules/controllers/home.php

     $result = modules::run("apis/c_$api/data", $parameters); var_dump($result); //works
  2. modules/apis/controllers/c_api1.php

     function data() { #.... case 'getDataInfo': echo 'baa'; //Not working $result = simplexml_load_string($this->api1->getDataEntry($parameters['id'], false)); var_dump($result); //Not working break; #.... }

Any ideas why this happens? The fact that returning $result works but not the echo or var_dump()

Update

The function works because if I comment the $result line inside the case, I have no output. That means that the case works, but even so I don't get the echo

I think that MX HMVC extension blocks in some way the output of a module when called via Modules::run .

Here is a small piece of MX's Modules.php, you can see that the output is not sent to the browser but returned instead:

ob_start();
$args = func_get_args();
$output = call_user_func_array(array($class, $method), array_slice($args, 1));
$buffer = ob_get_clean();
return ($output !== NULL) ? $output : $buffer;

As far as I know there is no way to send something to the output calling a module with Modules::run unless you want to modify the code above.

That's why you are able to print $result on the caller controller and not on the invoked one.

You need to return what you want to print so that you can print it on the caller side.

The most obvious cause would be that case is not being matched.

Without seeing more of api1.php , I am forced to speculate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM