Re: access to object methods (not properties) from within templates

From: Date: Tue, 22 Jan 2002 15:08:36 +0000
Subject: Re: access to object methods (not properties) from within templates
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2563@lists.php.net to get a copy of this message
On Mon, 21 Jan 2002, Marko Kind wrote: > 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... You should take a look at ext/overload extension that I put into CVS a couple of months ago. It lets you do exactly that. Any access to $obj->foo gets translated to a call to object's __get() function. See README file in the extension's directory. -Andrei "Computers are useless. They can only give you answers." --Pablo Picasso

« previous php.smarty.general (#2563) next »