RE: [SMARTY-DEV] object registration committed

From: Date: Fri, 24 Jan 2003 02:24:15 +0000
Subject: RE: [SMARTY-DEV] object registration committed
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-610@lists.php.net to get a copy of this message
I like the '.' syntax personally. I do have a question about the object support though. I use arrays of objects a lot in my applications. Usually as far as the template is concerned they have been used as containers. With the ability to call object methods from the template I see the huge gains for me. Now, can I call object methods from within a {section}, {foreach}, etc? I would think so, but thought I would ask. A simple example of the syntax would be handy here. Thanks, Steve -----Original Message----- From: Monte Ohrt [mailto:monte@ispi.net] Sent: Thursday, January 23, 2003 3:44 PM To: Smarty Dev Subject: [SMARTY-DEV] object registration committed Support for object registration has been committed to CVS. I'm wondering which syntax would be best, "." or "->": {foo.bar} {foo->bar} {foo.bar p1="foo"} {foo->bar p1="foo"} The first is shorter and an existing syntax, the second is more consistant with the longer object syntax and is distinct, possibly avoiding future syntax collisions. So which is better, existing syntax or distinct, more consistant syntax? as of now (in CVS) it is foo.bar but easily changed. Monte On Thu, 2003-01-23 at 14:50, Monte Ohrt wrote: > OK so here's a proposal how object registration could work. > > First off, having to register each method is kind of tedious. Typically > you would want to register an entire object, but optionally limit the > methods/properties that can be accessed. > > With that in mind, I'd like to try this template syntax: > > {foo.bar p1="blah" p2="blah"} > > Where foo is the object, and bar is the method. This gives a syntactical > distinction between template functions and objects, thus allowing access > to arbitrary methods within an object. This will also make parsing > easier. > > Since functions and objects look and work differently, separate API > calls should probably be used. Registering an object could work like so: > > $smarty->register_object('foo', $objfoo); > $smarty->register_object('foo', $objfoo, > array('meth1','meth2')); > $smarty->register_object('foo', $objfoo, null, true); > > * Objects are always registered by reference. > * The second example limits access to the methods "meth1" and "meth2". > Parameters are passed much like template functions, where an array is > passed as argument 1, and the Smarty object is passed as argument 2. > * The third example registers the object such that parameters are passed > in the traditional sense, one var per argument. > * Security settings are honored for private method access. > * Special parameter "assign" will assign the output instead of > displayed. > > As far as method vs. property, maybe we go with the idea that a method > takes precedence over a property of the same name? Otherwise we have to > make a syntactical distiction like {foo->bar} for properties. > > Monte -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

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