Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM Troubles - Getting infomation
  • Hi there. Below is some code I'm using to pull out 'sites' registered to a 'user'. However I don't know how to get to the sites that are been pulled through. When I do a
    var_dump($this->user)
    
    I can see them, but when I call
    var_dump($this->user->sites);
    
    it throws an error saying :"ErrorException [ Notice ]: Trying to get property of non-object" Can anyone show me what I'm missing!?
    Here is my code:
    $this->user = Model_Users::find()
        ->related('sites')
        ->where('username', '=', \Session::get('username'))
        ->get();
    var_dump($this->user->sites);
    

    Cheers,
    Steve
  • Always read the output of a var_dump very carefully, or there's no use to getting it. The get() method returns an array of objects, if you want an individual object you need to use get_one() instead.
  • Thanks for that! fixed it for this case. Cheers for the speedy reply. I saw it was an array and so tried var_dump($this-user[0]); but that came up with an error too. Anyway, it's sorted now. Thanks!
  • They're indexed by their primary key(s), which should also have shown when you var_dump() the $this->user variable.

Howdy, Stranger!

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

In this Discussion