Jump to content

Output Buffering help needed.


Vander

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.