Re: [SMARTY] DB_DataObject and Smarty
[email protected] (Ken Snyder) Thu, 05 Oct 2006 14:42:29 -0600
| Newsgroups | php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
Yes, you probably do need to implement the iterator interface in the
users class. I believe that Smarty uses foreach loops for all iteration
so that objects with iterator interfaces can be used. You should also
get the same error/result if you were to add the following to sandbox.php:
foreach( $users as $user ) {
echo "Current User: ".$user['id']."<br>";
}
--Ken
Chris Boget wrote:
> Does anyone know of any tutorials out there that show how I can get
> smarty working with DBDO? I've searched but haven't been able to come
> up with anything beyond using DB::getAll() method. I'd rather stay
> away from using that if at all possible. I'd rather use DBDO::find().
> Here's one (among many) attempt I made to get it to work:
>
> sandbox.php:
> <?php
> $users = new Users();
> $users->country = 'USA';
> $users->limit( 10 );
> $users->find();
>
> $smarty = new Smarty();
> $smarty->assign( 'users', $users );
> $smarty->display( 'sandbox.tpl' );
>
> ?>
>
> sandbox.tpl
> <html><head><title></title></head><body>
> {section name=bar loop=$users}
> Current User: {$users[bar].uid}<br>
> {/section}
> </body></html>
>
> but doing that gives me an error saying that it cannot use object of
> type Users as array. Am I just doing it wrong? Do I need to
> implement the iterator interface in the Users class?
>
> If someone can offer any pointers as to what I'm doing wrong or if you
> can point me to a howto/tutorial on the web, that'd be awesome!
>
> thnx,
> Chris