Config Static Variables Not Working |
Hi,
I am using a custom Config file. I populate its static variables by calling a method & then use those variables in BaseController. Its working fine in BaseController but when I try to use those same variables in AdminController extended from BaseController its variables show empty. I don't call the method to populate its variables in AdminController as its extended from BaseController. Following are details. Kindly help me understand why config file variables don't show any value in AdminController: BaseController PHP Code: $this->config = config('My_config'); AdminController extends BaseController PHP Code: $this->config = config('My_config'); $this->config::$users_array[0]; prints values in BaseController but don't print anything in AdminController. Please advise. Regards
look this my config
PHP Code: <?php namespace Modules\Common\Config;
Enlightenment Is Freedom
config is mean for variable and value (for stand alone purpose) , others better use models or library
(08-03-2021, 07:20 PM)paulbalandan Wrote: Do not call `config` again in AdminController Then how to access config in Admin Controller? I tried calling PHP Code: parent::$users_array[0]; PHP Code: $this->$users_array[0]; As config is not an object, its just loaded and used & the variables are static so how I should access them in Admin Controller?
What is the visibility of $this->config in BaseCOntroller? If set to private, AdminController can't access it. Needs to be at least protected or public.
(08-03-2021, 09:36 PM)paulbalandan Wrote: What is the visibility of $this->config in BaseCOntroller? If set to private, AdminController can't access it. Needs to be at least protected or public. I am just accessing it using PHP Code: $this->config = config('My_config'); PHP Code: $this->config::load_values(); As per documentation // Get shared instance with config function $config = config('Pager');
Ok. I meant how you define it in your class?
PHP Code: class BaseController (08-03-2021, 10:15 PM)paulbalandan Wrote: Ok. I meant how you define it in your class? I dont declare any variable like this. I think the real question is that I access a shared instance using $this->config = config('My_config'); and then populate its static variables like following: $this->config::load_values(); Now as the variables in 'My_config' are static, they must maintain the values throughout the life of the process so when I access the same shared instance using $this->config = config('My_config'); in another controller, it should have the static values intact. But actually they have empty values. Why? Either $this->config = config('My_config'); creates a new instance & dont provide the shared instance or there is a way to access the static variables that I am unaware of.
I think I have a guess on the problem but needs some confirmation.
Can you share the code of your My_config? Class objects are saved by reference by default so changing one should affect the other. I just need to confirm the structure of your config class to know the culprit behind this. |
Welcome Guest, Not a member yet? Register Sign In |