Redroest Posted September 2, 2010 Share Posted September 2, 2010 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 More sharing options...
justsomeguy Posted September 2, 2010 Share Posted September 2, 2010 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 More sharing options...
Redroest Posted September 2, 2010 Author Share Posted September 2, 2010 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 More sharing options...
justsomeguy Posted September 2, 2010 Share Posted September 2, 2010 You don't name the buffers, they get cleared in the reverse order in which they were created. Last-in-first-out, the last to get created is the first to get cleared. Link to comment Share on other sites More sharing options...
Redroest Posted September 2, 2010 Author Share Posted September 2, 2010 Aw omg I made one little error. I've been struggling with it for over 2 days now and now suddenly it works just as you say.. Don't really know what went wrong though!Thanks anyway Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.