如何在CodeIgniter中覆盖控制器中的配置数组?

asp*_*aga 2 php multidimensional-array codeigniter-2

我有一个文件app/config/template.php:

$config['head_meta']        = array(
    'charset'       => 'UTF-8',
    'description'   => '',
    'keywords'      => '',
    'stylesheets'   => array(
        'template.css'
    ),
    'scripts'       => array(
        'plugins/jquery-2.0.3.min.js',
        'plugins/bootstrap.min.js'
    ),
    'end_scripts'   => array(
        'template.js'
    )
);
Run Code Online (Sandbox Code Playgroud)

我需要在控制器的函数中覆盖该描述app/controllers/pages.php:

function contact($pagename = 'Contact', $slug = 'contact'){

    // load dependencies
    $this->load->library('form_validation');
    $this->lang->load($slug);

    // page settings
    $this->config->set_item('page_name',    $this->lang->line('menu_subtitle_contact'));
    $this->config->set_item('page_slug',    $slug);
    $description = $this->config->item('description', 'head_meta');
    var_dump($description);

    $data['view'] = $this->load->view($slug, '', TRUE);
    $this->load->view('templates/default', $data);

}
Run Code Online (Sandbox Code Playgroud)

我怎么想这样做?在CI2的文档中,有一个示例来覆盖config的值,如下所示:$this->config->set_item('configItem', 'value');

但是如果我的配置项是一个数组应该怎么样?我试过$this->config->set_item('description', 'head_meta', 'NewValue');但它没用

谢谢你的建议

Has*_*ami 5

不幸的是,通过使用$this->config->set_item('item_name', 'item_value');,无法更改配置值中的特定数组项.

您可能必须获取当前配置值,修改它并再次设置它:

$this->config->set_item('head_meta', array_merge(
    $this->config->item('head_meta'), array('description' => 'newValue')
));
Run Code Online (Sandbox Code Playgroud)