Re: [SMARTY-DEV] Re: object support
| From: | Bharat Mediratta | Date: | Mon, 13 Jan 2003 18:45:36 +0000 |
| Subject: | Re: [SMARTY-DEV] Re: object support | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-526@lists.php.net to get a copy of this message | ||
Thanks for considering this.
From: "Monte Ohrt" <monte@ispi.net>
...
> This sounds like a sound solution, I like the registering idea. I think
> there still needs to be a distinction between function calls and object
> calls:
I respectfully disagree. A template designer does not need to know
the underlying technology behind a template call. As far as a template
designer is concerned, he/she is given a very simple API with functions
and parameters and shouldn't have to know *anything* about how that
API is implemented. A template designer cannot be expected to know
anything about OOP and so these differences in syntax are going to
be confusing. I don't want to have to explain anything about OO in
my "how to write a template" docs!
...
> and doesn't mask the object model, but I think it is a good idea to make
> a distinction between them. This keeps the template functionality
> consistant, and also makes debugging/maintentance easier when you can
> see the difference between a function call and object call in the
> template.
From a debugging point of view, I contend that since the developer
is providing access to very specific aspects of the object's API,
it should not be too confusing. However, I understand that this
may not make sense for very large projects which are giving access
to extensive APIs.
> To be able to access an object, it must be registered:
>
> $smarty->register_object('theme', $theme,
> array('foo','bar','blah'));
>
> This will register the object by reference. The third parameter sets
> what methods are accessible from the template. If no third parameter is
> given, then all methods are accessible, except for internal methods
> which begin with "_"
I definitely like this (especially since I'm using the _ for my
private methods so I wouldn't have to go changing a lot of code).
It's also far more efficient than the hack I was using.
Would it be possible to compromise and use a syntax like this?:
{theme.foo p1="blah"}
This is somewhat similar to our existing ${array.member} syntax so it
will be a little more recognizeable to a template designer while still
providing a clue to the developer that this is an OO callback. I have
not looked under the covers so I don't know how difficult that might
be to implement.
Thanks again,
-Bharat