Re: [SMARTY] how to register an array with objects?

Jochem Maas <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
Martin Anders wrote:
> hi folkz,
> 
> it is very easy to register a single object. but how can i register an array with objects?
> 
> 
>         $myArray = array();
> 	for ($i=0; $i<10; $i++)
> 	{
> 		$myArray[$i] = new My_Object();
> 	}
> 	
> 	// $smarty->register_object("myArray", ...); ?????

I have never used the register_object function, I always just assign
the objects as I would any other kind of variable... but then as far as
Smarty is concerned what I do with (php5) objects is evil. :-)

> 	$smarty->assign('myArray', $myArray);
> 	
> 
> 
> 
> 
> 	TEMPLATE:
> 	{* here i want to use the My_Object-objects *}
> 	{foreach from=$myArray item=myObj}
> 		property: {$myObj->someProperty}<br>
> 	{/foreach}

question: does it work when you try this?
hint:	  trying it is a good idea.
answer:   yes|no (delete as applicable)

free [evil] info:
$myArray can even be an object itself, although you
use it like an array, if:

1. you are using php5+
2. you are using Smarty2.6.8+
3. the object implements the Iterable interface (It may be a different interface,
I can't remember, the maddening ammount of 'strange' interfaces in SPL make my
head spin a little - now where did I leave that
RecursiveRecursiveIteratorIteratorIterator implementation? ;-)


> _________________________________________________________________________
> Mit der Gruppen-SMS von WEB.DE FreeMail können Sie eine SMS an alle 
> Freunde gleichzeitig schicken: http://freemail.web.de/features/?mc=021179
> 

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.