Re: Smarty Patch: Calling class methods in templates / Object handling

From: Date: Sun, 08 Dec 2002 01:03:13 +0000
Subject: Re: Smarty Patch: Calling class methods in templates / Object handling
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-383@lists.php.net to get a copy of this message
Hi Andre, Is this going into the next version of Smarty? I've been writing PHP using classes for quite a while and the first problem I encounter when I tried to convert some existing work to use Smarty is precisely this one! Thanks, Anson "Andr?Rabold" <arabold@nero.com> wrote in message news:20021206123252.25458.qmail@pb1.pair.com... > Hi again, > > I have (nearly) finished my patch for Smarty to support class methods in > your templates too not only class variables. > Here are some examples what smarty is able do right now and whats not: > > {$myObject->variableName} works as expected > {$myObject->getVar("variableName")} throws an "unknown tag" error :-( > > {foreach from=$myObjectArray item="obj"} > {assign var="xyz" value=$obj->variableName} > {/foreach} > works as expected > > {foreach from=$myObjectArray item="obj"} > {assign var="xyz" value=$obj->getVar("variableName")} > {/foreach} > throws an error that $obj is no object :-( > > --------- > > These errors occures because smarty doesn't accept class methods but only > variables. After modifications on three > Smarty_Compiler.php lines these are supported too now. > > Even modifiers on class methods are supported: > {$myObject->getVar("variableName")|lower} > > I haven't found any side effects yet. All is working as expected. Please let > me know if you find any errors. > > --------- > MODIFICATIONS FOR SMARTY 2.3.1: > > Line 238: > if > (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+))*(\(.*? > \))?(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // > if a variable > > Line 1080: > $var_exprs = > preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(\(.*?\))?) > )*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); > > Line 1119: > preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+(\(.*?\))?|^\w+(\(.* > ?\))?!', $var_ref, $match); > > --------- > CVS > > cvs diff Smarty_Compiler.class.php (in directory C:\CVS-Checkout\smarty\) > Index: Smarty_Compiler.class.php > =================================================================== > RCS file: /repository/smarty/Smarty_Compiler.class.php,v > retrieving revision 1.129 > diff -r1.129 Smarty_Compiler.class.php > 238c238 > < if > (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+))*(?>\|@ > ?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a > variable > --- > > if > (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+))*(\(.*? > \))?(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // > if a variable > 1080c1080 > < $var_exprs = > preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+))*(?>\|@?\ > w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); > --- > > $var_exprs = > preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(\(.*?\))?) > )*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens); > 1119c1119 > < preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+|^\w+!', $var_ref, > $match); > --- > > > preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+(\(.*?\))?|^\w+(\(.* > ?\))?!', $var_ref, $match); > > >

« previous php.smarty.dev (#383) next »