Dataset from database accessible on all controllers and views |
Hello thanks to the whole community and to whom you have dedicated your time to read this post.
The problem I have is that I have a table in the database called ´settings´ that inside has only two columns ´config_name´ and ´config_value´ with which I intend to control some functions of the application. The issue is that I capture all the data well but when I want to pass it globally so that all the drivers are able to read one or more given configurations, this does not happen, how can I do it? Greetings and thank you very much
I think that almost every developer had a similar problem. here is my solution for CI4.
App/Config/SiteSettings.php PHP Code: namespace Config; App/Models/SiteSettings.php PHP Code: namespace App\Models; Common.php PHP Code: if(!function_exists('configItem')) and further anywhere in the code in controller: $param_test = configItem('param_test', 'some_default_value'); or in view: <?php configItem('param_test'); ?> or in BaseController: $this->settings = config('SiteSettings'); at the same time, access to the database table occurs only once upon the first call of the config('SiteSettings')
Thank you very much for your input, something like this i have programmed, but i am using Codeigniter3 and I really can't find a way to make it work on CI3, Thanks
For CI3 the same thing can be done through the hook system
hooks/Site_settings_hook.php PHP Code: class Site_settings_hook { config/hooks.php PHP Code: $hook['post_controller_constructor'][] = array( as a result, all values from the database become available in the application config
Hello again, I have modified something in the code that you have put, because the CI super object did not work for me, in the end it was something like this:
PHP Code: class Site_settings_hook extends CI_Model { but I still have the same problem, I have to declare each variable in each controller for each view I want to use, I would like to know if it is possible to do something like what I have developed outside of codeigniter for another project, which is something like this: PHP Code: function obtain_config(){ PHP Code: $config = obtain_config() so with this code when I want to get the value of a row in the confi_name table I just have to write. PHP Code: $config ['row name'] ![]()
Hi
I have a little problem with this feature for CI4: I have a "home controller" where I would like to use a function to test whether the value for "siteOffline" is 1 or 0. If I query this directly in the controller, it works fine. But if I create a public function of it, it is simply ignored. Here is the code where my query works: HomeController PHP Code: class Home extends BaseController Here are the two snippets of code where it doesn't work: HomeController PHP Code: class Home extends BaseController Where is my mistake?!? Greetings, Kighlander
Hi
As a result of the is_offline function call, just the string will be returned. PHP Code: class Home extends BaseController Therefore, nothing further happens. If you change the function to an example like this PHP Code: public function is_offline() then after its execution either nothing will happen or the offline page will be shown.
|
Welcome Guest, Not a member yet? Register Sign In |