我有一个文件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的文档中,有一个覆盖config值的示例,如下所示:$this->config->set_item('configItem', 'value');
但是,如果我的配置项是一个数组,该怎么办呢?我试过$this->config->set_item('description', 'head_meta', 'NewValue');
,但不起作用
感谢您的建议
不幸的是,使用$this->config->set_item('item_name', 'item_value');
无法更改配置值中的特定数组项。
您可能需要获取当前的配置值,对其进行修改并重新设置:
$this->config->set_item('head_meta', array_merge(
$this->config->item('head_meta'), array('description' => 'newValue')
));