2

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?

2
  • 2
    Mmm, you are getting the value right, but your $config gonna be a string, so i think that foreach will not do what you expect. Commented Aug 4, 2014 at 19:43
  • What's the name of your new config file? Commented Aug 5, 2014 at 10:53

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.