|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Rogier21 Smarty n00b
Joined: 19 Dec 2009 Posts: 3
|
Posted: Sat Dec 19, 2009 1:59 pm Post subject: Apache crash on custom plugin |
|
|
Hello all,
In smarty 2 this used to work:
Code: |
Function Smarty_Function_Header($Params, &$Template)
{
Return $Template->Fetch(header.tpl');
}
|
Now I have transformed this to Smarty 3:
Code: |
Function Smarty_Function_Header($Params, $Smarty, $Template)
{
Return $Template->Fetch('header.tpl');
}
|
But now Apache crashes with the error:
Code: | Parent: child process exited with status 255 -- Restarting. |
That usually means an infinte loop somewhere.
Am I doing something wrong in the new version?
Thanks |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sat Dec 19, 2009 3:06 pm Post subject: |
|
|
Does PHP throw an error? |
|
Back to top |
|
Rogier21 Smarty n00b
Joined: 19 Dec 2009 Posts: 3
|
Posted: Sat Dec 19, 2009 3:34 pm Post subject: |
|
|
No nothing, just crash.
But I tried this (stupid that I didn't try that before)
Code: |
Function Smarty_Function_Header($Params, $Template)
{
Return $Template->Fetch('header.tpl');
}
|
So the signature has changed only from &$Template to $Template, and that works.
I don't know why the Smarty plugins use:
Code: |
function smarty_function_html_image($params, $smarty, $template)
{
|
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Dec 19, 2009 4:28 pm Post subject: |
|
|
In Smarty 3 the template object is passed as third parameter. You did call the fetch methode on the wrong object.
Wrong:
Code: | Function Smarty_Function_Header($Params, $Smarty, $Template)
{
Return $Template->Fetch('header.tpl');
} |
Right:
Code: | Function Smarty_Function_Header($Params, $Smarty, $Template)
{
Return $Smarty->Fetch('header.tpl');
} |
The template object does have also a fetch methode which was called in wrong context and did indead result in an endless loop.
Another note:
Why do you not use {include file='header.tpl'} but a fuction plugin?
You will lose some of Smarty's features like compile checking of subtemplates for cached pages and other when loading subtemplates by plugins. |
|
Back to top |
|
Rogier21 Smarty n00b
Joined: 19 Dec 2009 Posts: 3
|
Posted: Sat Dec 19, 2009 4:30 pm Post subject: |
|
|
U.Tews wrote: | In Smarty 3 the template object is passed as third parameter. You did call the fetch methode on the wrong object.
Wrong:
Code: | Function Smarty_Function_Header($Params, $Smarty, $Template)
{
Return $Template->Fetch('header.tpl');
} |
Right:
Code: | Function Smarty_Function_Header($Params, $Smarty, $Template)
{
Return $Smarty->Fetch('header.tpl');
} |
The template object does have also a fetch methode which was called in wrong context and did indead result in an endless loop.
Another note:
Why do you not use {include file='header.tpl'} but a fuction plugin?
You will lose some of Smarty's features like compile checking of subtemplates for cached pages and other when loading subtemplates by plugins. |
Because this is a stripped down version, I add different kind of things like checking if somebody is loggedin, but also adding javascript and CSS files etc.
But what is the 3rd param used for? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Dec 19, 2009 4:44 pm Post subject: |
|
|
There are plugins thinkable which may need access to the properties and methodes of the template objects because of the new structure of Smarty 3. |
|
Back to top |
|
|
|
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
|