Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Cannot use object of type stdClass as array

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sunzi
Smarty n00b


Joined: 09 May 2006
Posts: 3

PostPosted: Wed May 10, 2006 7:20 am    Post subject: Cannot use object of type stdClass as array Reply with quote

Hello There,

sorry, but Im a newbie with smarty.
I get this erroe message:
Cannot use object of type stdClass as array
the php-script
-->
if($count == 1)
{
$invs = $db->get_results("select * from inventory");
$smarty->assign('inventory', $invs);
$smarty->display('inv.tpl');
}
else
{

<--

the template
{foreach item=inven from=$inventory}
{$inven.id} {$inven.vorname} {$inven.name} {$inven.team} {$inven.role} {$inven.computerType} {$inven.model} {$inven.hardwareDetails} {$inven.serviceTag} {$inven.deliveryDate} {$inven.screen} {$inven.licenseSoftware}<br>
{/foreach}

The array is filled fine, I print_r in php, but when I use the template i get
the error message.

Please help.

Thanks

Sun
Back to top
View user's profile Send private message
andreas
Smarty Pro


Joined: 22 Apr 2003
Posts: 106

PostPosted: Wed May 10, 2006 11:09 am    Post subject: Reply with quote

You have to use the variable syntax for object properties in your template:

http://smarty.php.net/manual/en/language.syntax.variables.php

Or you have to change your DB object to return arrays not objects for result sets.
________
vaporizer pipe
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP