Jump to content

ob_flush()


Destramic
Go to solution Solved by Destramic,

Recommended Posts

hey guys...im having a issue when using ob_flush()...what im getting is a 1 at the end of my html depending on how many templates i render...in this instance i get 11 at the end of my html in the browser,

 

render in my view class:

	public function render($file_name)
	{	
		if (preg_match("/\.html$/i", $file_name))
		{
		    ob_start();
			extract($this->_variables);
			require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file_name;
		    $body = ob_flush();
		}
 
	   $this->_repsonse->append_body($body);
	} 

inside my controller:

$this->view->render('template.html');

template.html

my header is here

<? $this->view->render('content.html') ?>

my footer here

how the source looks in browser:

my header is here

content is here

my footer here11

any idea why i get 1's after my html when using ob_start() please?

 

thank you

Link to comment
Share on other sites

Have you tried commenting out the output buffer block of code to verify that's what's causing the issue? For example, you could try something like this:

public function render($file_name)
{ 
    /*
    if (preg_match("/\.html$/i", $file_name))
    {
        ob_start();
        extract($this->_variables);
        require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file_name;
        $body = ob_flush();
    }
    */
 
    $body = "<div>All good here ($file_name)</div>";
    $this->_repsonse->append_body($body);
}
 
Perhaps the issue is caused by append_body()...
Link to comment
Share on other sites

Well, I assume that the following line of code would display content on the screen without buffering the output:

require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file_name;

Instead of displaying it directly to the screen, it looks like you want to assign the content to $body. If that's correct, you would use ob_get_contents(). Note that this function doesn't clear the buffer, so you'll need to also call ob_end_clean().

 

You could try changing this

public function render($file_name)
{ 
    if (preg_match("/\.html$/i", $file_name))
    {
        ob_start();
        extract($this->_variables);
        require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file_name;
        $body = ob_flush();
    }
 
    $this->_repsonse->append_body($body);
}

To this

public function render($file_name)
{ 
    if (preg_match("/\.html$/i", $file_name))
    {
        ob_start();
        extract($this->_variables);
        require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file_name;
        $body = ob_get_contents();
        ob_end_clean();
    }
 
    $this->_repsonse->append_body($body);
}
Link to comment
Share on other sites

  • Solution

Typo?

 

$this->_repsonse->append_body($body);

$this->_response->append_body($body);

 

thanks for that :)

 

 

 

ob_flush(), contrary to the manual, appears to return true (1)

ob_start();
echo "";
$body = ob_flush();
var_dump($body);      //--> bool(true)
		if (preg_match("/\.html$/i", $file_name))
		{
		    ob_start();
			extract($this->_variables);
			require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file_name;
			$body = ob_get_contents();
		    ob_clean();
		}
 
	   $this->_response->append_body($body);

solved it now...thanks for your input guys :)...much appreciated

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.