Jump to content

Outputbuffering multiple times


Redroest

Recommended Posts

Hey, I am working on a system that includes modules by using outputbuffering. The following function loads files from modules. The output generated by the module will be checked for so called "custom tags" and replaces them with modules. These modules will then be included into a template for example.

<?phpfunction file_to_var($file){  if (is_file($file))   {	ob_start();//Load the modulefile	include($file);	$content = ob_get_contents();	ob_end_clean();		return $content;  }}?>

This code works fine to me, but there is one problem. I just made a module in another system. This system has no outputbuffering and my module works fine in it. Here comes the problem:The module contains its own outputbuffering (I made a photoalbum manager using the JUpload applet which uses ob_start.To simplify:

<?phpfunction file_to_var($file){  if (is_file($file))   {	ob_start();//Load the modulefile	include($file);//Module also contains ob_start()//as simulated on the below line:	ob_start();	$content = ob_get_contents();	ob_end_clean();		return $content;  }}?>

As you can see and guess, the module will be outputted before the rest of the themplate and appears on top of the website.How to prevent this from happening? I don't want to modify every class, module or function that contains outputbuffering.

Link to comment
Share on other sites

If you're going to rely on output buffering then I don't see any other way other than changing everything else that uses output buffering. There are multiple levels of buffers that you can use, so I guess it depends what the other files are doing with output buffering. If an include file starts a new buffer without clearing it then that's a problem.

Link to comment
Share on other sites

Well is it possible to group the buffers? like below???

<?php//Start primary bufferob_start('primary');//Start secondary buffer (for example in a function)ob_start('secondary');//End secondary bufferob_end_clear('secondary');//End primary bufferob_end_clear('primary');?>

On php.net they say that ob_start() is a function that nests.. like:

<?php//Start primary bufferob_start('primary');//Start secondary buffer (for example in a function) //This will output the first bufferob_start('secondary');//End bufferingob_end_clear('secondary');?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...