Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Catchable fatal error: Object of class stdClass could not be

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
gremio10
Smarty Rookie


Joined: 28 Jan 2011
Posts: 11

PostPosted: Wed Mar 16, 2011 2:20 am    Post subject: Catchable fatal error: Object of class stdClass could not be Reply with quote

Hello,

I use the PDO conection, and when I make a Query with fetchAll he returns a stdClass, how I do to make a foreach?

I make like this:

php.:

Code:
$names      = $Sql->findAll("User",array("select" => array("name","email")));

$smarty->assign("name",$names);
$smarty->display("index.tpl");


tpl.:

Code:
{foreach from=$name item=names}
   {$names}
{/foreach}


my fetchAll().:

Code:
public function fetchAll(){
      
      try{
         
           return $this->qry->fetchAll( PDO::FETCH_OBJ );
         
      }catch( PDOException $e ){
         
         print( $e->getMessage() . " - [ " . $e->getCode() . " ] " );
            
      }
      
    }


Thank You.
Back to top
View user's profile Send private message Send e-mail
scdgro
Smarty Regular


Joined: 24 May 2003
Posts: 39
Location: Netherlands

PostPosted: Sat Mar 19, 2011 12:34 pm    Post subject: Reply with quote

Don't know if this is what you mean :

Smarty 2 syntax :
Code:

{foreach from=$name item=names}
   {$names->foo}
   {$names->bar}
{/foreach}


Smarty 3 syntax :
Code:

{foreach $name as $names}
   {$names->foo}
   {$names->bar}
{/foreach}
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development 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