我有一个小问题。我有一个用于上传的自定义配置文件。我想加载设置而不重新定义它们。
好的,我的配置如下:
config.php
$config['upload_path'] = 'tmp/';
$config['allowed_types'] = 'zip';
$config['file_name'] = '';
$config['max_size'] = '';
$config['encrypt_name'] = false;
$config['remove_spaces'] = true;
Controller
// Here is my problem $config[]
// How to load settings from config.php without again defining $config array
$config['upload_path'] = $this->config->item('upload_path');
$config['allowed_types'] = $this->config->item('allowed_types');
$config['file_name'] = $this->config->item('file_name');
$config['max_size'] = $this->config->item('max_size');
$config['encrypt_name'] = $this->config->item('encrypt_name');
$config['remove_spaces'] = $this->config->item('remove_spaces');
$this->load->library('upload',$config);
if(!$this->upload->do_upload())
{
$this->session->set_flashdata('error', $this->upload->display_errors());
redirect('extension/');
}
我想绕过$ config ['test] = $ this-> config-> item('test');的重新定义;
这不可能吗?
我不确定是否遗漏了一些东西,只是不要将这些行放在您的控制器中。这实际上不会重新声明吗?
http://ellislab.com/codeigniter/user-guide/libraries/config.html描述如何加载自定义配置项目。我建议按照CI网站的建议创建一个自定义配置文件,然后将其加载到您想要的位置。
所以您将拥有$this->config->load('custom_upload_settings', FALSE, TRUE);
之类的东西,并且在该文件中,您具有要覆盖的设置。
//加载名为custom_upload_settings.php的配置文件,并将其分配给名为“ blog_settings”的索引$this->config->load('custom_upload_settings', TRUE);
//检索custom_upload_settings数组中包含的名为site_name的配置项$site_name = $this->config->item('site_name', 'custom_upload_settings');
是,Codeigniter支持自定义上传配置。您可以设置config / upload.php初始设置。
[另一个控制器;
$config['upload_path'] = FCPATH . 'assets/uploads/articles'; // change custom config
$this->upload->initialize($config, FALSE);
最重要的初始化第二个参数是FALSE。该参数与RESET有关。在保留默认的上传设置的同时,您可以更改其他设置。