Destramic Posted June 9, 2015 Share Posted June 9, 2015 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 Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 9, 2015 Share Posted June 9, 2015 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()... Quote Link to comment Share on other sites More sharing options...
Destramic Posted June 9, 2015 Author Share Posted June 9, 2015 thanks for your post if i use $body = ob_get_contents(); instead then i get no 11 at end of the </html> tag...as for it being the response there's nothing in there that could cause it... =/ Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 9, 2015 Share Posted June 9, 2015 Yeah, you're right. That seems odd since ob_flush() isn't supposed to return anything. Quote Link to comment Share on other sites More sharing options...
Destramic Posted June 9, 2015 Author Share Posted June 9, 2015 any ideas on how i can sort this please? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 9, 2015 Share Posted June 9, 2015 any ideas on how i can sort this please? What do you mean by "sort this"? Is the program still not working? Or are you trying to change the sort order of something? Quote Link to comment Share on other sites More sharing options...
Destramic Posted June 9, 2015 Author Share Posted June 9, 2015 well its ob_flush() i need to use...but still getting the return of 1's at the end of the html...so i meant how to sort so it stops showing the 1's? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 9, 2015 Share Posted June 9, 2015 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); } Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted June 10, 2015 Share Posted June 10, 2015 Typo? $this->_repsonse->append_body($body); $this->_response->append_body($body); Quote Link to comment Share on other sites More sharing options...
Barand Posted June 10, 2015 Share Posted June 10, 2015 ob_flush(), contrary to the manual, appears to return true (1) ob_start(); echo ""; $body = ob_flush(); var_dump($body); //--> bool(true) Quote Link to comment Share on other sites More sharing options...
Solution Destramic Posted June 11, 2015 Author Solution Share Posted June 11, 2015 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.