Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to add a function to ORM Model
  • Hi, I'm new to FuelPHP, and my PHP is rusty - I apologise if this is massively obvious! I have a fixture model (generated with OIL), which represents a rugby match. The model has a 'home_team' property, which is a key to the teams table. When displaying fixtures in the admin panel (or anywhere really) I'd obviously like to display the team names rather than their IDs. So, I added the following function to my fixture model: public static function getHomeTeamName() {
    return Model_Team::find($this->home_team)->name;
    } Then in my view, I simply want to echo $fixture->getHomeTeamName(); However, I get an error (using $this in a non-object context). Am I on the right lines? Or would I be better doing this with a DB join in the first instance?
  • Moved to the ORM forum.
  • There is no $this in a static context, so you can not do that. If you want to have the method operate on the object level, do not define it as static.
  • That makes sense, I was removing static because of this - but adding an extra $ like so: $this->$home_team; Which was obviously undefined! Thanks.

Howdy, Stranger!

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

In this Discussion