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

Call static functions without assiging an object

 
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
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Thu Oct 28, 2010 1:01 pm    Post subject: Call static functions without assiging an object Reply with quote

It is possible to write fairly complex Smarty Template tags. The one that saved my time was the ability to call static methods, without assigning any object.

Code:

{tools::random_text(6)}
{tools::random_text($length)}


and a real life example is:
Code:
<a href="results.php?random={tools::random_text($length)}">Results</a>
which helps to force reloading the results.php page, without caching in the browser.

Much interesting is that $length is a Smarty variable, and not a regular PHP variable. But the compiled files produce results as expected.

tools is a class, having random_text() as static function.
Back to top
View user's profile Send private message Visit poster's website
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