Error when accessing base controller variable - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Error when accessing base controller variable (/showthread.php?tid=76885) |
Error when accessing base controller variable - campingrhino - 06-29-2020 Hi there, I'm hoping someone can help. I've got a class that I'm using in my controllers and libraries to handle settings that are stored in the database. When accessing them in my controller via $this->settings->get('blah'), I have no problems at all. However, when I pass $this->settings in the controller's __construct() to my template library, it's passing a null value and I get this error: Quote:TypeError I've loaded the library in the base controller as shown below. This is my BaseController: PHP Code: public $session, $settings; This is the Settings class: PHP Code: class Settings { And finally my controller itself: PHP Code: class AccountController extends BaseController Any help would be greatly appreciated! Thanks. RE: Error when accessing base controller variable - captain-sensible - 07-02-2020 this is how i'm setting some BaseController , class member properties public function __construct() { helper(['text', 'date']); $this->theTime = now('Australia/Victoria'); $this->theDate = date("d/m/Y",$this->theTime); } RE: Error when accessing base controller variable - ojmichael - 07-02-2020 Your issue is the class constructor will run before initController method. Use this instead. PHP Code: class AccountController extends BaseController |