Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Extra Fields in Model
  • Hello all, How can you have extra fields in the model that are made of data from the database but aren't store in the database themselves? For example if I was making a blog and I wanted a field in the model called $link:
    $this->link = "/post/".$this->id So I need a function that is called after the model has loaded, seems like this should be simple but I can't figure it out. Any ideas?
  • You'd need to declare those properties as public properties within the class, you can't set them once the object has been created because the magic __set() method will catch it. To populate it you'll probably need to write an observer for your model that runs on the 'after_load' event: http://fuelphp.com/docs/packages/orm/observers/creating.html Another solution would be to use a method instead, just add a method to your model called link() that creates the value on the fly and returns it.
  • I thought about the observer but it seemed overly complicated. I'm going to go for the method option - it looks a bit ugly but it works. Thank you.

Howdy, Stranger!

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

In this Discussion