Welcome Guest, Not a member yet? Register   Sign In
Setting in database
#4

[eluser]Pascal Kriete[/eluser]
Code:
class Settings {
    
    var $CI;
    var $options;
    
    /**
     *Constructor
     *
     * @access    public
     */
    function Settings()
    {
        $this->CI =& get_instance();
        $this->options = array();

        // Load database class
        $this->CI->load->database();

        // Get global variables
        $this->_init();
    }

    // ------------------------------------------------------------------------    
    
    /**
     * Set settings
     *
     * @access    private
     */
    function _init()
    {        
        $this->CI->db->select('varname, value');
        $query = $this->CI->db->get('setting');

        if ($query->num_rows() == 0)
        {
            show_error('Could not get settings from DB');
        }

        foreach($query->result() as $row)
        {
            $this->options[$row->varname] = $row->value;
        }
    }
}

Put that in a library and autoload it. Now all your settings should be available through $this->settings->options['whatever'].


Messages In This Thread
Setting in database - by El Forum - 06-11-2008, 08:41 AM
Setting in database - by El Forum - 06-11-2008, 09:01 AM
Setting in database - by El Forum - 06-11-2008, 09:17 AM
Setting in database - by El Forum - 06-11-2008, 09:29 AM
Setting in database - by El Forum - 06-17-2008, 07:53 PM
Setting in database - by El Forum - 06-17-2008, 08:33 PM
Setting in database - by El Forum - 06-17-2008, 08:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB