Re: [SMARTY-DEV] Re: object support

From: Date: Thu, 23 Jan 2003 20:50:02 +0000
Subject: Re: [SMARTY-DEV] Re: object support
References: 1 2 3 4  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-607@lists.php.net to get a copy of this message
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 On Thu, 2003-01-23 at 03:23, Jan Rosier wrote: > Hello Monte, > > I like this idea of having an standard mode and an advanced mode. In > standard mode the different parts get assign in bits and pieces which does > give maximum controle and an pre defined space ( sandbox ;-) ) to play in > for the template designer. > > If you don't need all the controles. You can go for the advanced mode. Which > makes it possible to assign the hole thing at once and give / have access to > the hole playground, but it also makes change of having an accident bigger > :-) > > Greetings, > Jan Rosier > > > > So what if we support both methods? The preferred method of using > > objects will be to register them and use them like regular template > > function calls. This has several limitations, but will probably work > > fine for typical use, and _especially_ those of us who have to train and > > support a diverse field of template designers. OTOH, If you want to > > access an object directly in the template, Smarty will recognize and > > support that as well. Supporting OO syntax in the template is not a > > technical barrier, the whole issue is requiring a new syntax for the > > HTML designers to understand just so we can support object access. > > > > So two ways to use objects: > > > > PREFERRED, PREACHED METHOD: > > 1) Registering of object methods as template functions: > > > > php code: > > $smarty->register_function('themeFoo', array(&$theme, 'foo')); > > > > template: > > {themeFoo p1="foo" p2="bar"} > > > > > > NOT PREFERRED, BUT SUPPORTED METHOD: > > 2) assign objects, access them directly: > > > > php code: > > $smarty->assign_by_ref('theme',$theme); > > > > template: > > {$theme->foo("foo","bar")} > > > > > > It will be clearly stated in the manual the difference between the two > > methods, why use one over the other, etc. We already have issues like > > this in Smarty, where there is nothing stopping you from mixing PHP code > > in the templates but it is highly discouraged, so this really wouldn't > > be any different. > > > > Would this satisfy both sides of the fence? > > > > Monte > > -- Monte Ohrt <monte@ispi.net>

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