![]() |
Error when trying to get property from parent class - 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 trying to get property from parent class (/showthread.php?tid=80266) |
Error when trying to get property from parent class - boddah85 - 10-10-2021 It looks I'm missing something. I'm trying to get property value from parent class (BaseController) and im getting "Trying to get property 'saveUserLog' of non-object". App\Controllers\UserLog Code: <?php namespace App\Controllers; App\Controllers\BaseController.php Code: class BaseController extends Controller App\Config\SiteConfig Code: <?php namespace Config; Thanks in advance for any help. RE: Error when trying to get property from parent class - InsiteFX - 10-11-2021 Change it from private to protected. public scope to make that property/method available from anywhere, other classes and instances of the object. private scope when you want your property/method to be visible in its own class only. protected scope when you want to make your property/method visible in all classes that extend current class including the parent class. RE: Error when trying to get property from parent class - paulbalandan - 10-11-2021 Looking at your BaseController it seems there is really no $saveUserLog property. RE: Error when trying to get property from parent class - boddah85 - 10-12-2021 (10-11-2021, 07:32 PM)paulbalandan Wrote: Looking at your BaseController it seems there is really no $saveUserLog property. As I said before, maybe Im missing something but for saveUserLog is property from config object (App\Config\SiteConfig). In BaseController I have $siteCfg property and then im checking $this->siteCfg->saveUserLog. InsiteFX Wrote:Change it from private to protected.Which one? siteCfg property is protected. RE: Error when trying to get property from parent class - paulbalandan - 10-13-2021 You said you are trying to access the property from the parent class, to which I assumed you defined it as an explicit property. Anyway, move the initialization of $this->siteCfg from the initController method into the __construct method. |