View previous topic :: View next topic |
Author |
Message |
BoA456 Smarty n00b
Joined: 04 May 2016 Posts: 4
|
Posted: Wed May 04, 2016 10:36 pm Post subject: Smarty Template destroying ob_start() |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu May 05, 2016 1:44 pm Post subject: |
|
|
Move all presentation code to Smarty. |
|
Back to top |
|
BoA456 Smarty n00b
Joined: 04 May 2016 Posts: 4
|
Posted: Thu May 05, 2016 2:17 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu May 05, 2016 2:52 pm Post subject: |
|
|
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 |
|
BoA456 Smarty n00b
Joined: 04 May 2016 Posts: 4
|
Posted: Thu May 05, 2016 4:08 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu May 05, 2016 10:42 pm Post subject: |
|
|
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 |
|
BoA456 Smarty n00b
Joined: 04 May 2016 Posts: 4
|
Posted: Sat May 14, 2016 7:08 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun May 15, 2016 12:55 am Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun May 15, 2016 10:56 am Post subject: |
|
|
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 |
|
|