How to Access Config File Variables Globally in all Views ? - 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: How to Access Config File Variables Globally in all Views ? (/showthread.php?tid=74935) |
How to Access Config File Variables Globally in all Views ? - midhunlalkc - 11-27-2019 How to access config file variables Globally in all views without passing it from controller? i have a config file : app/config/SiteConfig.php PHP Code: <?php namespace Config; Now am passing it from controller like this PHP Code: <?php Is there any better way to accomplish this without passing it from every controller methods? RE: How to Access Config File Variables Globally in all Views ? - MGatner - 11-27-2019 Anything you load in BaseController will be available in all the controllers that extend it. There is also the helper function “config()” which not only fetches a config but can use it immediately, e.g.: <a href=“https://google.com/maps?key=<?= config(‘SiteConfig’)->googleMapsApiKey ?>”>Click</a> RE: How to Access Config File Variables Globally in all Views ? - midhunlalkc - 11-27-2019 (11-27-2019, 04:52 AM)MGatner Wrote: Anything you load in BaseController will be available in all the controllers that extend it. There is also the helper function “config()” which not only fetches a config but can use it immediately, e.g.: This is exactly what am looking for. Thank You so much. RE: How to Access Config File Variables Globally in all Views ? - Lauren - 04-05-2020 We must be require to define some global value for application like number of pagination records, user type, site url etc. if you are working with small project then walgreenslistens i will suggest to create global config file for define constants variable. |