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

Best way to clone smarty instance

 
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
mwvdlee
Smarty Rookie


Joined: 05 Nov 2011
Posts: 7

PostPosted: Fri May 20, 2016 10:16 pm    Post subject: Best way to clone smarty instance Reply with quote

I'm currently using `clone` to make copies of a Smarty instance to render multiple templates roughly as such:

Code:

function getSmarty() {
   static $smarty = null;

   if (!$smarty) {
      $smarty = new Smarty();
      // ...all kinds of plugins, and setitngs here...
   }

   $instance = clone $smarty;
   $instance->clearAllAssign();
   $instance->clearConfig();
   return $instance;
}


The primary reason for this construction is to share the compile caching in memory, other than that, the instances should look like clean instances.

The question is; will this work as a way to generate new Smarty instances or will instances returned by this function interfere with each other? Or perhaps there is a better way to do this?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat May 21, 2016 2:41 am    Post subject: Reply with quote

I don't understand, what you are trying to achieve here.
Are you rendering more than one response in a single request?
Then http://www.smarty.net/forums/viewtopic.php?p=90107#90107 may be a better option.
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