Error when trying to get property from parent class |
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.
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Looking at your BaseController it seems there is really no $saveUserLog property.
(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.
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. |
Welcome Guest, Not a member yet? Register Sign In |