Reply to Re: [SMARTY] looping over an array of objects

Your name:

Reply:


Posted by Erik Schmitt on 11/01/05 17:41

Hello,

if you want to iterate over an array holding propel objects: it works.

I read your question on the propel list and I am not sure if I understood
it correctly. Is it your intention to "convert" values of propel objects
into an multidimensional-array?

Anyway, this works:

{foreach from=$USER_ARRAY item=USER}
{$USER->getName}<br/>
{/foreach}

(And this will not work: {$USER->getCompany()->getName()} )

- Erik


Am Dienstag, 1. November 2005 14:40 schrieb Isaac Vetter:
> I'm setting up propel (http://propel.phpdb.org/), which is an
> object-relational mapper, like DB_Object. So, database queries return
> objects, many of which need to be passed to a smarty template for
> display. I could manually move each relevant property into an array
> ($ary[$i]['id'] = $aryOfObj[$i]->getId()), but ... I really don't want
> to have to do that.
>
> The smarty documentation implies that an array of objects can be looped
> over, if the array is assign()'d or assign_by_ref()'d. This doesn't
> seem to be working for me. Can someone confirm that this works?
>
> If this doesn't work, I'm thinking of writing/using code that uses
> reflection to automatically call property getters to create the
> smarty-required multi-dimensional arrays, any suggestions?
>
> Much Thanks,
>
> Isaac Vetter
>
>
> -----------------------------------------
> Smarty allows access to PHP objects through the templates. There are two
> ways to access them. One way is to register objects
> <http://smarty.php.net/manual/en/api.register.object.php> to the
> template, then use access them via syntax similar to custom functions.
> The other way is to assign objects
> <http://smarty.php.net/manual/en/api.assign.php> to the templates and
> access them much like any other assigned variable. The first method has
> a much nicer template syntax. It is also more secure, as a registered
> object can be restricted to certain methods or properties. However, *a
> registered object cannot be looped over or assigned in arrays of
> objects*, etc. The method you choose will be determined by your needs,
> but use the first method whenever possible to keep template syntax to a
> minimum.
>
> http://smarty.php.net/manual/en/advanced.features.php#advanced.features.objects
>
>
>
>
>

--
Mit freundlichen Grüßen
Erik Schmitt

e-novum Software GmbH
D-49078 Osnabrück, Heger-Tor-Wall 19,
Fon.: +49 (0)541 440 630 - 25, Fax: - 26
E-Mail: mailto:e.schmitt@e-novum.com

---------------------------------------------------------
e-novum ® Software ist eine gute Wahl für Ihr E-Business.
Finden Sie heraus warum. www.redpart.de / www.e-novum.com

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация