Suggestion: Add a multiple assignment function to the OutlineTpl class.

0 views
Skip to first unread message

Ibmurai

unread,
May 27, 2009, 6:46:18 AM5/27/09
to php-outline
Something like this:

public function assignMultiple($array) {

/*
Exposes the given values as template variables with the names $key
and the values $val.
*/
foreach($array as $key => $val)
$this->vars[$key] = $val;

}

mindplay.dk

unread,
May 27, 2009, 7:32:22 PM5/27/09
to php-outline
How about something like this:

public function apply($array, $overwrite = true)

I like short function names - and optionally skipping variables that
are already assigned could be useful if you want to apply some
defaults to templates you reuse a lot :-)

mindplay.dk

unread,
May 27, 2009, 11:22:36 PM5/27/09
to php-outline
Try updating from SVN - the apply() method is available now. Let me
know how it works for you.

I also added an expose() method, which works for objects - this should
be great when used with something like Outlet:

http://www.outlet-orm.org/

Using the $full parameter, you can optionally expose protected and
private members, too.

This gives you an easy way to expose object members to a template,
without exposing the object itself.

On May 27, 6:46 am, Ibmurai <ibber_of_cre...@hotmail.com> wrote:

Ibmurai

unread,
May 28, 2009, 12:55:47 AM5/28/09
to php-outline
Expose should work brilliantly. My custom database handler class can
return rows as objects (or associative arrays).

I'm going to try it out today :)

Ibmurai

unread,
May 28, 2009, 2:05:21 AM5/28/09
to php-outline
As it turns out it doesn't make sense to use expose for my database
rows, so I'll have to try it out, when I get object oriented on my
project :)

apply works perfectly, though, for me at least, it makes more sense
for overwrite to default to false...
If you think about it, overwrite can't really be a boolean, since
there should be three options:
1) FULL_OVERWRITE, clears all template variables and assigns the new
ones. (default right now)
2) OVERWRITE, overwrites existing template variables when they
conflict with the new ones. (should be default, imo)
3) STRICT, is like OVERWRITE but throws exceptions on conflicts.

There may even be a fourth and a fifth which I just haven't thought
about :D
Reply all
Reply to author
Forward
0 new messages