Passing in objects by reference (Pull approach w/ Smarty)
| From: | Oleg Rekutin | Date: | Thu, 05 Jul 2001 04:24:23 +0000 |
| Subject: | Passing in objects by reference (Pull approach w/ Smarty) | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-1114@lists.php.net to get a copy of this message | ||
I am using PHP to develop a web application, which borrows ideas on
actions, screens, templates, layouts, etc from Apache Jarkata projects
Turbine and Velocity (jakarta.apache.org).
One aspect is that every page of the site is represented with a
corresponding screen template (1-to-1 relationship). There are also
layout templates that envelop the screen templates.
In this application, I'm also trying to use a so-called "Pull model",
overview of which you can read at <http://jakarta.apache.org/turbine/pullmodel.html>.
Basically, instead of preparing specific information to be displayed
by the screen template and then passing that information on to the
template, the application simply exposes a number of business logic
objects (or something like that), "tools", and places them into the
global "context".
For example, there is a security tool (a class, really) with methods
add_user, get_all_users, get_permissions_for_role, get_roles_for_user,
and such. The idea is that the screen template that lists all users,
simply does foreach($security->get_all_users() as $user) and then
has the repeating listing part inside the foreach statement.
The whole application has only one "document" php file, index.php. It
is responsible for inserting all the context tools into the namespace
of all templates (screen and layout), so that the templates can refer
to them, and then displays a particular screen template (specified via
a parameter) along w/ the enclosing layout templates.
Now, for my templates, I just include .php files. In those files, I
only make calls to provided tools and use basic stuff like control
structures.
I found out about Smarty and it looks like a useful template engine,
so far the best out of all others available (I have not liked a single
PHP template engine available on the web).
So here's my question. Is it possible to pass in objects to Smarty
templates by reference? Something like assign("security",
$context->get('security'));, where all method calls to security within
the Smarty templates are performed on the reference returned by
Context::get. This way, only one copy of the security object is
maintained, and thus only one state is updated.
For instance, all screen templates do $context->set('title', 'Log in') and
then the layout template displays $context->get('title') in the
<title></title> tags. This requires that the screen template modifies
one and only one context object, thru a reference, so that the layout
template can retrieve the set value from the same object.
However, as far as I see, assign() takes in the value by parameter and
not reference. Is there any way to have some sort of "assign_by_ref"?
TIA,
Oleg