CodeIgniter Forums
_output called, but $output is empty - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: _output called, but $output is empty (/showthread.php?tid=39310)



_output called, but $output is empty - El Forum - 03-07-2011

[eluser]Unknown[/eluser]
I have a method in my controller

Code:
function test() {
  print "test";
}

function _output($output) {
   var_dump($output);
}

_output() is being called, but $output is blank, and the output is sent, so that I see "test" first, then the var dump of an empty string.

I don't have caching on, no compression, no hooks, nothing I can see that would cause this. Any suggestions?

Thx,

Tac


_output called, but $output is empty - El Forum - 03-07-2011

[eluser]oldmatt[/eluser]
I don't see in your question where you have defined
Code:
$output

I think I am missing something.


_output called, but $output is empty - El Forum - 03-08-2011

[eluser]InsiteFX[/eluser]
Did you look at CodeIgniters Output Library?

InsiteFX


_output called, but $output is empty - El Forum - 03-08-2011

[eluser]WanWizard[/eluser]
CodeIgniters Output library calls _output() in your controller if it exists, passing all buffered output to it:
Code:
if (method_exists($CI, '_output'))
{
    $CI->_output($output);
}
else
{
    echo $output;  // Send it to the browser!
}

The problem here is that direct output generated in the controller by things like echo, print, or var_dump are not buffered by the Output library, which is probably why $output is empty.