|
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 |
Slarioux Smarty n00b
Joined: 30 Nov 2004 Posts: 2
|
Posted: Tue Nov 30, 2004 8:23 am Post subject: Using a class inside a custom function |
|
|
---
Last edited by Slarioux on Wed Aug 26, 2015 7:24 am; edited 1 time in total |
|
Back to top |
|
Slarioux Smarty n00b
Joined: 30 Nov 2004 Posts: 2
|
Posted: Tue Nov 30, 2004 8:27 am Post subject: |
|
|
---
Last edited by Slarioux on Wed Aug 26, 2015 7:23 am; edited 1 time in total |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Nov 30, 2004 3:17 pm Post subject: |
|
|
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 |
|
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
|