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

Using a class inside a custom function

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
Slarioux
Smarty n00b


Joined: 30 Nov 2004
Posts: 2

PostPosted: Tue Nov 30, 2004 8:23 am    Post subject: Using a class inside a custom function Reply with quote

---

Last edited by Slarioux on Wed Aug 26, 2015 7:24 am; edited 1 time in total
Back to top
View user's profile Send private message
Slarioux
Smarty n00b


Joined: 30 Nov 2004
Posts: 2

PostPosted: Tue Nov 30, 2004 8:27 am    Post subject: Reply with quote

---

Last edited by Slarioux on Wed Aug 26, 2015 7:23 am; edited 1 time in total
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Nov 30, 2004 3:17 pm    Post subject: Reply with quote

There are several techniques but I will show the most straight-forward:

Say that your class for which $sql is instanced contained a method (we'll call it as in your example, but it can have any name): smarty_function_bar(). We can register that method as a custom callback function with Smarty (note: you can do this in the constructor of your custom extended Smarty class)

$smarty->register_function('bar', array(&$sql, 'smarty_function_bar');

The difference here is that your plugin is not autoloaded but rather always loaded since you must first load and instantiate your class for this to work.

If you are using an OOP framework you might consider using singletons, but I will leave that as an excercise for you Smile
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 -> Tips and Tricks 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