Using custom_result_object |
Hi!
I'm trying to figure out how to use the "custom_result_object" and I need something which is very similar to the example in the documentation. The date is stored in a table as a unix timestamp and would like to have it returned as a human readable date. https://codeigniter.com/user_guide/datab...lt-objects So I figured I'd give "custom_result_object" a try because it could come in handy in some other spots. Model: PHP Code: public function get_shortlink_list($team = 0, $order = 0, $limit = 0, $offset = 0) { The Shortlink_List.php contains: PHP Code: <?php The part of the controller using this: PHP Code: public function links() { The result I'm getting is: Fatal error: Call to a member function format() on string in Even though I've followed the example in the documentation very closely. Any ideas / hints would be appricated. Thanks, jay
Jay,
I have no idea why it isn't working (it should, I went and tracked down the custom_result_object code and it is solid). The shortlink_list class's __set isn't being called (at least that's what my quick test revealed) I put echo/die() in the __set before anything else and it never triggered, so, protected/private vars are assigned from and the __set is ignored. The workaround I did on it was to move the assignment line in to the timestamp function, like so: PHP Code: public function timestamp($format) I'm very certain there is a better way to do that, but that's the quick and dirty to get what you're looking for in the mean time.
In your class "Shortlink_list" remove this:
PHP Code: protected $timestamp; Then the class will call the __set and the correct value will populate. (did for me). So you can remove the setting the value in the timestamp function. |
Welcome Guest, Not a member yet? Register Sign In |