Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty Template destroying ob_start()

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
BoA456
Smarty n00b


Joined: 04 May 2016
Posts: 4

PostPosted: Wed May 04, 2016 10:36 pm    Post subject: Smarty Template destroying ob_start() Reply with quote

Hi,

i have a central index.php which dynamically includes that site that needs to be rendered. Because i sometimes need to use header() calls i enclosed my central index.php inside ob_start(); and ob_end_flush(); to not let the HTML out until everything is finished.

Problem:
Inside my navigation i recently added 2 calls to $smarty->display() which will break my site. The template both calls simply display is a normal HTML template, nothing special inside there. Why does it break my ob_start()? Remember: Everything is encapsulated insite ob_start() and ob_end_flush(). It should not break out and not go in the buffer. But it does.

Also:
My index.php looks something like this:

Code:
// ob_start()
<body>

<nav>
// include nav.php here which renders the navigation and has the  2 $smarty->display() calls which will break my site
</nav>

// here include the page which is currently needed and process / render it
// in this process i am calling ALOT of other $smarty->display() and they will simply WORK and not mess up my ob_start(). Why do they work but the ones started by the include_once("nav.php"); a few lines above do not work?

</body>

// ob_end_flush()


Thanks for your help! I searched hours for an answer to this but can not get it to work.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu May 05, 2016 1:44 pm    Post subject: Reply with quote

Move all presentation code to Smarty.
Back to top
View user's profile Send private message
BoA456
Smarty n00b


Joined: 04 May 2016
Posts: 4

PostPosted: Thu May 05, 2016 2:17 pm    Post subject: Reply with quote

AnrDaemon wrote:
Move all presentation code to Smarty.


Yes, i will do that. Will take a lof of time since this is legacy code however. But: Why does this error occur i described in my post? How can i fix it? Why is it that smarty breaks my ob_start()?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu May 05, 2016 2:52 pm    Post subject: Reply with quote

Your problem is that you used wrong solution to a problem.
Instead of wrapping your code into ob_*, enable output buffering in the PHP itself.
Doesn't make the problem any less of a problem, but at least, you will get rid of the intermittent "headers already sent" issue.
Back to top
View user's profile Send private message
BoA456
Smarty n00b


Joined: 04 May 2016
Posts: 4

PostPosted: Thu May 05, 2016 4:08 pm    Post subject: Reply with quote

AnrDaemon wrote:
Your problem is that you used wrong solution to a problem.
Instead of wrapping your code into ob_*, enable output buffering in the PHP itself.
Doesn't make the problem any less of a problem, but at least, you will get rid of the intermittent "headers already sent" issue.


Hm, ok. When i look in my php.ini i however see:
oututput_buffering 4096 4096

So its definitely on. Aleast thats what i read in http://php.net/manual/en/outcontrol.configuration.php.

Still it won't work. Still getting cannot mody header(). What did i miss here?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu May 05, 2016 10:42 pm    Post subject: Reply with quote

It _may_ still happen, if you have sent more data already, than a buffer may hold.
In which case, seriously, with all due haste convert your code to using Smarty.
Trust me, it'll be much cleaner and smaller within a week, and will only keep improvind from there.
Back to top
View user's profile Send private message
BoA456
Smarty n00b


Joined: 04 May 2016
Posts: 4

PostPosted: Sat May 14, 2016 7:08 pm    Post subject: Reply with quote

AnrDaemon wrote:
It _may_ still happen, if you have sent more data already, than a buffer may hold.
In which case, seriously, with all due haste convert your code to using Smarty.
Trust me, it'll be much cleaner and smaller within a week, and will only keep improvind from there.


For anyone else having this problem - this was the problem (smarty bug), updating fixed it: https://github.com/smarty-php/smarty/issues/187
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun May 15, 2016 12:55 am    Post subject: Reply with quote

That was not necessarily a Smarty bug.
I've long since stopped using "?>" in scripts myself, causes too much problems in unexpected places.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun May 15, 2016 10:56 am    Post subject: Reply with quote

Smarty versions 3.1.28 and 3.1.29 did flush output buffering which caused the problem.
The fix is in the master branch and will be included in 3.1.30
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP