Welcome Guest, Not a member yet? Register   Sign In
Dataset from database accessible on all controllers and views
#4

For CI3 the same thing can be done through the hook system

hooks/Site_settings_hook.php
PHP Code:
class Site_settings_hook {
    function load() {
        $site_config = [];
        $ci = & get_instance();
        
        $qid 
$ci->db->query("SELECT config_name, config_value FROM settings");
        
        
if($qid && $qid->num_rows() > 0) {
            foreach($qid->result() as $row) {
                $site_config[$row->unit_name] = $row->unit_value;
            }

            $config = & get_config();
            
            $config 
array_merge($config$site_config);
        }
    }


config/hooks.php
PHP Code:
$hook['post_controller_constructor'][] = array(
    'class'    => 'Site_settings_hook',
    'function' => 'load',
    'filename' => 'Site_settings_hook.php',
    'filepath' => 'hooks'
); 

as a result, all values from the database become available in the application config
Reply


Messages In This Thread
RE: Dataset from database accessible on all controllers and views - by vitnibel - 06-18-2020, 09:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB