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

Go To StackoverFlow.com

1

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

2012-04-04 21:47
by Alex


1

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.

2012-04-04 22:13
by Dalen
ok I see! Are you aware of any fixes for this matter - Alex 2012-04-04 22:20
I'm not aware of any configuration that makes the Modules::run 'print'. Just print it on tha caller sid - Dalen 2012-04-04 22:23
I understand, I wanted to print inside module just for more debugging features. But I decided to try save the data to a variable from print dump echo or what ever outputting function, and print it again inside the caller - Alex 2012-04-04 22:25
please add my solution that I wrote in the comment so I can accept your message - Alex 2012-04-05 10:08


0

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

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

2012-04-04 21:52
by wallyk
that's the problem, IT IS matched! It returns $result but does not the bloody echo. Lo - Alex 2012-04-04 21:54
If the output from echo is not switched off, then it must be executing another module, another function, or with different data - wallyk 2012-04-04 21:55
no, because if I comment the $result line... I have no output. I know, it's strange and it's freaking me out x - Alex 2012-04-04 21:58
maybe you don't see output because of there is redirect in some place ? add exit(); after var_dum - Fivell 2012-04-04 22:03
check @Dalen 's answer because it seems to have a really good logic - Alex 2012-04-04 22:28
Ads