Welcome Guest, Not a member yet? Register   Sign In
Database-based configuration library/model?
#1

[eluser]tolyx[/eluser]
Hi -

Does anyone know about or has developed a db-based configuration library or model?

I'd love to be able to

a) Return config values from a database table of one row, whose field names are of all different types so that I can return:

$this->db_config->email_address;

b) Save new config values easily:

$this->db_config->save('email_address'=>'[email protected]');

c) Automatically generate form elements depending on the db field types - e.g. a text field for VARCHAR and textarea for TEXT

Any ideas before I attempt to do it myself?

Dan.
#2

[eluser]TheFuzzy0ne[/eluser]
I haven't seen such a library. It sounds like what you need is very specific, so you'd probably be better off writing your own library. Be careful, though, as a lot of CodeIgniter's configuration data needs to be made available before the database is loaded.
#3

[eluser]Daniel H[/eluser]
Sorry I should be clear that this is for non-core CI config items, such as email addresses etc. that will need to be updated by a user.
#4

[eluser]Mushex Antaranian[/eluser]
I'm using model for it, like OpenBlog.. hope it will help you

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Db_settings_model extends Model
{
    public $table = 'settings';
    // Constructor
    public function __construct()
    {
        parent::Model();
    }

    function get_settings($name = '')
    {
        $this->db->select('name, value');
        if ($name != '') {
            $this->db->where('name', $name);
        }
        $query = $this->db->get($this->table);
        if ($query->num_rows() > 0)
        {
            $result = $query->result_array();
            foreach ($result as $row)
            {
                $settings[$row['name']] = $row['value'];
            }
            return $settings;
        }
    }

    function set_settings($settings = array())
    {
           foreach ($settings as $name => $value) {
            $this->db->set('value', $value);
            $this->db->where('name', $name);
            $this->db->update($this->table);;
        }
    }
?>

If any questions, feel free to email me jesirobendebua@gmail )




Theme © iAndrew 2016 - Forum software by © MyBB