Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM foreach statement
  • Hello! I've been trying to create a foreach statement for the longest time now using orm. Basically all I need to do is fetch all the posts from the db and loop them.
     public function get_all_posts()
     {
      $thought = Model_Post::find('last');
      
      return $thought;
     }
    
    if I do the following.
     public function get_all_posts()
     {
      $thought = Model_Post::find('All');
      
      return $thought;
     }
    
    and I get
       Notice!
       ErrorException [ Notice ]: Trying to get property of non-object
    

    What am I doing wrong?
  • Seen a few questions now on how to process ORM results. Maybe ask FrenkyNet to put up some examples in the docs.
  • You don't really need a separate function for what you're doing... so inside of your controller do this... That's an odd exception to be getting though... have you made a Model_Post model in your model folder?
    $thoughts = Model_Post::find('all');
    
    foreach ($thoughts as $thought)
    {
        // Do something...
    }
    
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion