DataMapper - How to execute method immediately after GET |
[eluser]Genki1[/eluser]
How to run a method immediately after an object is GET? I see the "get_rules" feature but it seems to apply to a single field whereas I want to manipulate several fields at once. For example, immediately after GETting a table record, I want to run my_custom_function() which operates on various fields and updates some class properties, like this: Code: function _my_custom_function() Should I create a get_rule for any random field (say, the ID field) and then call my function, like this? Code: var $validation = array( Reference: get_rules: http://datamapper.wanwizard.eu/pages/getrules.html
[eluser]WanWizard[/eluser]
The proper way is to overload the get() method. You could do it this way, it's just not that clean or transparent.
[eluser]Genki1[/eluser]
Thanks for that info. So, I've been researching this but don't understand how to overload the get() method. My mind is now, well, overloaded :-) Would you kindly provide an example of how to accomplish this?
[eluser]WanWizard[/eluser]
In your model: Code: public function get($limit = NULL, $offset = NULL) Note that get() can return multiple objects, so if you want to modify or add something, do not modify $this, but iterate over $this->all and modify those objects. The first object in the "all" array is a reference to $this, so by doing this you automatically modify the object itself as well...
|
Welcome Guest, Not a member yet? Register Sign In |