Problem with returned from the database in class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: Problem with returned from the database in class (/showthread.php?tid=67454) |
Problem with returned from the database in class - phpforever2017 - 02-24-2017 Hello. CodeIgniter 3.1.3 problem in the following PHP Code: class User_lib { model PHP Code: public function get_customer() controller PHP Code: public function index() results PHP Code: D:\Ampps\www\igniter\application\controllers\Welcome.php:26: PHP Code: D:\Ampps\www\igniter\application\controllers\Welcome.php:30: Why are set value to non-public properties. In guide: The object will have all values returned from the database set as properties. If these have been declared and are non-public then you should provide a __set() method to allow them to be set. Sorry for my English RE: Problem with returned from the database in class - Wouter60 - 02-25-2017 Please explain what the problem is. RE: Problem with returned from the database in class - ignitedcms - 02-26-2017 And use code tags. RE: Problem with returned from the database in class - Wouter60 - 02-27-2017 You were asking why the object properties are not public. Well, maybe because you declared them as protected in the User_lib class yourself? PHP Code: class User_lib { If properties are public, you can set them anywhere in your application like this: PHP Code: $this->User_lib->email = '[email protected]'; If properties are private or protected, you need a __set() method inside your object to change the value. Like this: PHP Code: public function __set($name, $value) This is a so-called magic method. It will be automatically called when you try to change the value of a non-public property. RE: Problem with returned from the database in class - phpforever2017 - 02-27-2017 The problem in the next, is not called __set method if set private or protected propeties. Yet I have done so: PHP Code: class User_lib { And __set method now work RE: Problem with returned from the database in class - Wouter60 - 02-27-2017 Glad to hear that it's working now (???) RE: Problem with returned from the database in class - phpforever2017 - 02-28-2017 (02-27-2017, 12:42 PM)Wouter60 Wrote: Glad to hear that it's working now (???) Working, working))))) I still can not understand why the values are set to the closed variable if their name matches the name of the field in the database |