Re: [SMARTY-DEV] object problems
| From: | M Mohr | Date: | Tue, 21 Jan 2003 18:35:54 +0000 |
| Subject: | Re: [SMARTY-DEV] object problems | ||
| References: | 1 2 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-569@lists.php.net to get a copy of this message | ||
Hello,
On Tue, Jan 21, 2003 at 10:58:17AM -0600, Monte Ohrt wrote:
> That's pretty much the argument. The benefit of supporting access to
> objects in the templates is tremendous, but it would be even better if
> we could accomplish this without new template syntax. The template
> designer has no care about the underlying data structure, so why make a
> different syntax for it? The closest we've come is registering objects
> as functions, but this has many drawbacks. It is seems almost inevitable
> that a new syntax would be required (php-style object syntax), unless we
> can figure out another way that will work.
>
> Monte
>
> On Tue, 2003-01-21 at 10:48, Dennis Gearon wrote:
> > I wonder in all this object talk if having objects available to the:
> >
> > DESIGNERS, HTML MONKEES, GRAPHIC DESIGNERS, et. al
> >
> > fits the goal of a template engine? Are we crossing the border between code and display
> > separation?
> >
> > 1/21/2003 8:04:46 AM, Monte Ohrt <monte@ispi.net> wrote:
> >
> > >It seems the idea of using foo.bar for object syntax isn't working very
> > >well. Since objects can be assigned at runtime, there is no way to know
> > >at compile time how to compile foo.bar, either as an array or as an
> > >object. The overhead of figuring this out at runtime isn't going to be
> > >worth it, so it must be compiled correctly. If we are going to support
> > >objects in Smarty, it is either going to have to have its own syntax, or
> > >we limit the use of objects by having all objects registered, meaning
> > >they must exist before the template is executed (or your runtime
> > >functions/objects register new objects on-the-fly)
> > >
> > >options:
> > >
> > >1) register all objects and methods:
> > >
> > >$smarty->register('myFoo', $my, 'foo');
> > >
> > >{myFoo p1="blah" p2="blah"}
> > >
> > >PROS: * no new syntax, looks just like a template function call.
> > >CONS: * cannot have arrays of objects to loop over
> > > * cannot pass object as parameter to function
> > > * every method must be registered before hand
> > > * property access?
> > >
> > >
> > >2) support new syntax for objects:
> > >
> > >{$foo->bar($foo, "bar", $blah[0].blah, nl2br($foo))}
> > >
> > >PROS: * mimics PHP native object syntax (?)
> > > * can pass object as parameter to function
> > > * can differentiate properties from methods
> > >CONS: * new template syntax introduced, now we pass
> > > parameters two different ways
> > > * may lead to new syntax problems, such as passing
> > > objects as parameters to objects
> > >
> > >
> > >We could go this route:
> > >
> > >{$foo->property}
> > >{$foo->method() p1="p1" p2="p2"}
> > >
> > >But is that much better than
> > >{$foo->bar("p1","p2")}
> > >
> > >The second one could be passed as a parameter, but not the first. But
> > >the first one does retain the parameter passing syntax.
> > >
> > >
> > >Any other thoughts/ideas, please do tell. I'd really like to figure out
> > >a way to use objects without new syntax or new style of passing
> > >parameters, but I don't know if that's feasible.
that is really a difficult situation. and maybe i can make it more
complicated, with another version :)
{$foo.property}
{$foo.method p1="p1" p2="p2"}
a method-call has to have at least one parameter, it would be treated as
a property otherwise.
if you really want to call a method without parameters you have to
indicate this explicitly
suggestions:
1. supply a dummy paramter (CON: a bit wordy)
2. {$foo.method } (CON: hard to distinguish to a property)
3. {$foo.method()} (ressembling php-syntax. CON: inconsistent)
4. {$foo.method ""}) (meaning "empty parameter-list". CON: inconsistent)
most of them are of course incosistent with smarty's existing syntax
and all of them are far away from perfect.
regards
messju
> > >Monte