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'
    )
);

我需要在控制器的函数中覆盖该描述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);

}

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

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

感谢您的建议

4

1 回答 1

6

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

您可能必须获取当前配置值,对其进行修改并重新设置:

$this->config->set_item('head_meta', array_merge(
    $this->config->item('head_meta'), array('description' => 'newValue')
));
于 2013-08-06T12:08:10.580 回答