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

Apache crash on custom plugin

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
Rogier21
Smarty n00b


Joined: 19 Dec 2009
Posts: 3

PostPosted: Sat Dec 19, 2009 1:59 pm    Post subject: Apache crash on custom plugin Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Dec 19, 2009 3:06 pm    Post subject: Reply with quote

Does PHP throw an error?
Back to top
View user's profile Send private message Visit poster's website
Rogier21
Smarty n00b


Joined: 19 Dec 2009
Posts: 3

PostPosted: Sat Dec 19, 2009 3:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat Dec 19, 2009 4:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
Rogier21
Smarty n00b


Joined: 19 Dec 2009
Posts: 3

PostPosted: Sat Dec 19, 2009 4:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat Dec 19, 2009 4:44 pm    Post subject: Reply with quote

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
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 -> Smarty 3 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