Re: Smarty and object support

From: Date: Tue, 17 Dec 2002 09:00:41 +0000
Subject: Re: Smarty and object support
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-425@lists.php.net to get a copy of this message
Great work! It works for me but there is one annoyance: {$foo->bar('blah','blub')} doesn't work because you only check for one parameter. I have modified Smarty_Compiler to allow multiple ones: Index: Smarty_Compiler.class.php =================================================================== RCS file: /repository/smarty/Smarty_Compiler.class.php,v retrieving revision 1.135 diff -r1.135 Smarty_Compiler.class.php 238c238 < if (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*\))*))*(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable --- > if (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*(\s*,\s*(?:'.$this->_qstr_regexp.')*)*\))*))*(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable 1077c1077 < $var_exprs = preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*\))?))*(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tokens); --- > $var_exprs = preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*(\s*,\s*(?:'.$this->_qstr_regexp.')*)*\))?))*(?>\|@?\w+(:(?>' . $this->_qstr_regexp . '|[^|]+))*)*$!', $tokens); 1131,1132c1131,1132 < < preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*\))?|^\w+!', $var_ref, $match); --- > > preg_match_all('!\[(?:\$\w+|\w+(\.\w+)?)\]|(->|\.)\$?\w+(?:\((?:' . $this->_qstr_regexp . ')*(\s*,\s*(?:'.$this->_qstr_regexp.')*)*\))?|^\w+!', $var_ref, $match); --------------------------------------------------------- I've just added (\s*,\s*(?:'.$this->_qstr_regexp.')*)* to allow multiple parameters. At this time no blanks are allowed between the parameters and the comma or it will result in a Smarty error (because Smarty interprets it as a Smarty function parameter {func param=1} and not as a method parameter). Now my application is working again. Woohoo! The only thing which I still would like to have are thing like NULL, TRUE and FALSE as parameters. Then you could do something like {$foo->bar(null,'blah')} which doesn't work right now. Even {$foo->bar(true)} isn't interpreted correctly. Perhaps the best thing would be a recursion for each specified parameter if an object's method is called. Then you could even use a syntax like {$foo->foo_it($bar->bar_it(true))} which looks a bit complex but is really usefull sometimes ;-) I'll try to implement this ... André "Monte Ohrt" <monte@ispi.net> schrieb im Newsbeitrag news:1040068296.11922.76.camel@lena.ispi.prv... > I committed to CVS, this syntax is now allowed: > > {$foo->bar('blah')} > {include file=$foo->bar('blah')} > {include file=$foo->bar->bar2->bar3->bar4('blah')} > > You can also embed template vars: > > {$foo->bar("you $foo")} > {include file=$foo->bar("this is $my var")} > > Please help test this, it affects many core components. > > Monte > >

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