Trying to get property of non-object - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Trying to get property of non-object (/showthread.php?tid=67730) |
Trying to get property of non-object - castle - 04-02-2017 Hello, My head is spinning and I cannot figure out why I'm getting the Trying to get property of non-object error. This is the error: PHP Code: A PHP Error was encountered And here comes the method from my Model: PHP Code: function is_added_by($type,$id,$user_id,$user_type = 'vendor') { Any help is appreciated! RE: Trying to get property of non-object - dave friend - 04-02-2017 As far as I can see the only object trying to access a property on that line is "db". Is the database lib loaded? Or it could also be that 'get_where' failed to find a record in the db in which case row() will return null. RE: Trying to get property of non-object - castle - 04-02-2017 The database is loaded. Is there any more info/code/log that I can provide here to help debug this issue? RE: Trying to get property of non-object - dave friend - 04-02-2017 The more I look at it the more certain I am that no matching record is found. I cannot tell you how many times I've been burned by thinking, "Well, I know that table is going to have data that matches the criteria I'm providing." It is wise to not assume anything. Try checking db results before proceeding. PHP Code: $query = $this->db->get_where($type,array($type.'_id'=>$id))->row(); RE: Trying to get property of non-object - castle - 04-02-2017 ...and you were right! Assumption is bad! :-) :-) Thank you very much! |