Undefined property: Admin::$db when I put database on autoload - 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: Undefined property: Admin::$db when I put database on autoload (/showthread.php?tid=68339) |
Undefined property: Admin::$db when I put database on autoload - desbest - 06-26-2017 I'm getting this error when trying to interact with the database with ORM. Undefined property: Admin::$db Stack Overflow says I should put database inside the libraries section of autoload.php I have already done this and I still get the error. It reads $autoload['libraries'] = array('database'); Please help. RE: Undefined property: Admin::$db when I put database on autoload - rtenny - 06-26-2017 I might be stating the obvious here but did you add the database credentials to config/database.php ? I use the above method all the time and never had any issues. Can you give us any other infos on this? RE: Undefined property: Admin::$db when I put database on autoload - desbest - 06-26-2017 Yes I did to that yes. It lets me access the database in the index() method for AdminController but not in the __construct() method in the AdminController Why would it let me access the database in one method but not other, if I have database autoload on? I'm using Windows 8.1 Also Code: <?php RE: Undefined property: Admin::$db when I put database on autoload - Martin7483 - 06-26-2017 When using a constructor you must first call the parent constuctor of CI_Controller PHP Code: public function __construct() |