Vander Posted January 24, 2011 Share Posted January 24, 2011 Please excuse me if I don't use appropriate formatting, I'm new here, however, this seems like a good place to come for help. What I am trying to do: I am trying to make a class that will handle my layouts. What problem I am encountering: When I run my script, I am getting this message. "Fatal error: ob_start() [<a href='ref.outcontrol'>ref.outcontrol</a>]: Cannot use output buffering in output buffering display handlers in C:\xampp\htdocs\core\main.php on line 17" Here is the code I am using. <?php class HTML{ private $header; private $footer; function __construct(){ ob_start(array($this,'callback')); } function callback($buffer){ $this->header(); $this->footer(); return $this->header.$buffer.$this->footer; } function header(){ ob_start(); // This is line 17 echo "header<hr />"; $this->header = ob_end_flush(); } function footer(){ ob_start(); echo "<hr />footer"; $this->footer = ob_end_flush(); } } $HTML = new HTML; ?> If anyone can help me, that will be great. Thanks, Alan Link to comment https://forums.phpfreaks.com/topic/225513-output-buffering-help-needed/ Share on other sites More sharing options...
Vander Posted January 24, 2011 Author Share Posted January 24, 2011 I seem to have managed to achieve my desired result, although, I'm not sure it's that great, I will however share what I've done incase this can better help someone to help me, or incase it can help others. <?php class HTML{ private $header; private $footer; function __construct(){ $this->header(); $this->footer(); ob_start(array($this,'callback')); } function callback($buffer){ $return = ''; $return .= $this->header; $return .= $buffer; $return .= $this->footer; return $return; } function header(){ ob_start(); echo "header<hr />"; $this->header = ob_get_contents(); ob_end_clean(); } function footer(){ ob_start(); echo "<hr />footer"; $this->footer = ob_get_contents(); ob_end_clean(); } } $HTML = new HTML; ?> What I did: Re-ordered when shit is called, i.e, I call the header and footer, store them in variables, then procced with the rest of the script, etc... I'm sure you can see what I done. Link to comment https://forums.phpfreaks.com/topic/225513-output-buffering-help-needed/#findComment-1164514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.