Re: assigned variable namespace updates
| From: | Andr� Rabold | Date: | Mon, 16 Dec 2002 10:44:12 +0000 |
| Subject: | Re: assigned variable namespace updates | ||
| References: | 1 | Groups: | php.smarty.dev php.smarty.general |
| Request: | Send a blank email to php-smarty-dev+get-415@lists.php.net to get a copy of this message | ||
*argh* That hits me hard :-(
Before your modifications I could use class methods as function
parameters...
{myFunc value=$myObject->getVar("myVar")}
$myObject->getVar("myVar") isn't parsed correctly by Smarty and
will not be compiled to $this->_tpl_vars["myObject"]->getVar("myVar").
Instead Smarty will leave the string as it is.
As long as "myObject" is in global namespace this works but after testing
the CVS version I recieve an error that "myObject" is no object which is
the result of your changes.
I want implement further updates of Smarty in my application so what do
you think about a flag to disable the new functionality? This would make
it possible for me to use further updates of Smarty.
Perhaps support for class methods should be implemented into Smarty
which is a heavy requested feature as I read in the newsboard. I have
already done some modifications to the Smarty_Compiler. You can read
about them in the posting titled "Smarty Patch: Calling class methods in
templates / Object handling".
If the parser could correctly handle constructs like the following it would
be really great:
{$foo->getVar($bar->getVar("field"))}
{fooFunction value=$foo->getVar($bar->getVar("field"))}
For if statements it already works as expected.
{if $API->isAuthorized($API->getCurrentModule(), _ACCESS_READ) }
is compiled to something like
if
($this->_tpl_vars["API"]->isAuthorized($this->_tpl_vars["API"]->getCurrentMo
dule(), _ACCESS_READ)
This is exactly what I want for both variable output ({$myVar}) and function
parameters ({myFunc value=$myVar}).
If this would work there would be no problems anymore ;-)
Thanks for reading,
André
"Monte Ohrt" <monte@ispi.net> schrieb im Newsbeitrag
news:1039711488.25435.39.camel@lena.ispi.prv...
> I just committed to CVS some new changes to Smarty, most notably
> assigned template variables are no longer extracted into global (PHP)
> namespace. This extraction was extraneous and takes processing time,
> more for every assigned variable. As a test, I made a template with 1000
> assigned variables. The execution time of this template was bettered by
> over 30%.
>
> As a consequence, there aren't issues with variable clashing in PHP
> namespace with assigned variables. We have to be careful with this,
> hopefully no one is using variables in a template that are not
> explicitly assigned. If you are, they won't show up anymore!
>
> Also, you can now embed variables in any quoted string, including
> modifier arguments.
>
> {include file="$template/foo.tpl"}
> {$foo|bar:"I am $name"}
> {$foo|bar:"I am \$name"} {* for literal value, escape with \ *}
>
> I unleashed it on our development CMS environment (good test for just
> about everything.) It all looks good initially, speed improvement is
> noticable!
>
> If you upgrade, do the usual:
> *) delete compiled templates
> *) delete cached files
> *) delete accelerator files
> *) restart apache
>
> Please help test if you can!
> Monte
>