Welcome Guest, Not a member yet? Register   Sign In
Unable to access variable
#6

(This post was last modified: 03-27-2022, 01:33 AM by spreaderman.)

@ vitnibel thanks. Did not realize that. I thought initController was more or less working as a __constructor. Is there any way to add a __constructor to initController? I am creating my cache in the BaseController which is a bunch of settings for my website. They are mainly required in the view so that works ok but I create my CSS, JS, etc, in the __construct part of my Public_Controller and need to know the cache setting then. I would like to keep the reading of cache in the base controller and have it loaded it first. Any ideas?

I guess one solution is

(1) insert below method into initController

Code:
    public function loadGlobalSettings()
    {
        $globalSettings = cache('global_settings');
        if (null === $globalSettings) {
            $globalSettings = cache('global_settings');
            $appSettingModel = model('\App\Models\AppSettingModel');
            $app_settings = $appSettingModel->getAppSettings();
            $globalSettings = [];
            foreach ($app_settings as $row) {
                $globalSettings[$row->app_setting_key] = $row->app_setting_value;
            }
            cache()->save('global_settings', $globalSettings, DAY*15);
        }
        return $globalSettings;
    }
(2) and then in the PublicController's __construct, call it like:

Code:
class Public_Controller extends BaseController{
        protected function __construct(){
        $site_settings = $this->loadGlobalSettings() ;
}

Something like above is ok?
Reply


Messages In This Thread
Unable to access variable - by spreaderman - 03-26-2022, 08:49 PM
RE: Unable to access variable - by kenjis - 03-26-2022, 08:59 PM
RE: Unable to access variable - by iRedds - 03-26-2022, 09:04 PM
RE: Unable to access variable - by spreaderman - 03-26-2022, 09:37 PM
RE: Unable to access variable - by vitnibel - 03-27-2022, 12:45 AM
RE: Unable to access variable - by spreaderman - 03-27-2022, 01:14 AM
RE: Unable to access variable - by vitnibel - 03-27-2022, 03:01 AM
RE: Unable to access variable - by spreaderman - 03-27-2022, 05:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB