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.