sorry, wrong email address - access to object methods...
| From: | Marko Kind | Date: | Mon, 21 Jan 2002 22:00:44 +0000 |
| Subject: | sorry, wrong email address - access to object methods... | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-2556@lists.php.net to get a copy of this message | ||
I APOLOGIZE FOR HAVING USED A WRONG EMAIL ADDRESS, THIS ONE IS CORRECT...
Hi all,
passing an object to a template allows me to access the object's properties. As the object doesn't know in advance _which_ properties will be accessed by the template, all property values have to have their "correct" values before I pass the object to the template (e.g. via "assign") - which may result in unnecessary DB queries, instantiation of other objects, HTTP requests - just whatever is needed to retrieve _all_ property values...
From my point of view it would be desireable if one could also call the object's methods from within the template. Then the object could dynamically retrieve and return the property values "on demand" avoiding unnecessary action for properties that aren't being used by the template at all.
I could think of two ways how this could be done:
i) allow the user to call any method:
{$object->getFoo()}
where $object provides method getFoo(). This way the template could do almost anything with the object.
ii) make it look like a property in the template and let the parser translate it to a method call:
TEMPLATE: {$object->foo}
translates to:
$object->foo();
or even:
$object->getProperty("foo")
I would prefer the latter solution as you don't have to provide one accessor method per property. In this case getProperty() is responsible for deciding whether it's necessary to retrieve a value and how to do it.
I've had a look at the Smarty classes and to me it looks like i) should be fairly easy to implement. ii) is much cleaner, I think, and produces less noise in the template...
I hope my ideas make sense. Sorry if this has been discussed before, I'm new to the list and the mailing list archive seems to be unreachable at the moment.
Thanks a lot in advance for your comments.
Regards
Marko