Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Formatting property value
I'd like to know whether it's possible to somehow change the value after loading it. In my case I have a updated_at column in my MySQL database, which is timestamp type, but I want to format the date in different format.
Is that possible?
Yes, you can use an observer.
We do the same in some apps, convert to a display format after read, and back to a timestamp on save.
I personally prefer not to alter data, but to deal with conversion on display, and after input processing. So the objects remain standard.
But don't forget a Model is a class any other, nobody is stopping you from adding a get_updatedat() method, that returns the timestamp in the format you want.
Thanks for your quick answer. How can I access the current data loaded?
The current model object is passed to the observer as the first parameter. So you have direct access to the object.
You can take for example the included createdAt and updatedAt observers as an example.
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion