user3897514
user3897514

Reputation:

Loading Config file in CodeIgniter Model

I am try to write code on this way. I wanna make new config file and load items from it

config file

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_encrypt_cookie']  = TRUE;

model

function item($key)
    {
        $data = array();
        $config = $this->config->item($key);
        foreach ($config as $row){
            $data = $row;
        }

        return $data['value'];

Am I on right way to do this in correct way?

Upvotes: 2

Views: 1343

Answers (1)

mrsrinivas
mrsrinivas

Reputation: 35404

Check below example to load other config file items.

Here I want access items from blog_settings.php (placed in config folder).

Now check this code to access that config file to get/set values

// Loads a config file named blog_settings.php and assigns it to an index named "blog_settings"
$this->config->load('blog_settings', TRUE);

// Retrieve a config item named site_name contained within the blog_settings array
$site_name = $this->config->item('site_name', 'blog_settings');

// An alternate way to specify the same item:
$blog_config = $this->config->item('blog_settings');
$site_name = $blog_config['site_name'];

Source : link (CI Documentation)

Upvotes: 1

Related Questions