2013-04-22 66 views
0

我有一個小問題。我有一個用於上傳的自定義配置文件。我想加載設置而不用重新定義它們。Codeigniter加載自定義上傳配置

好了,我的配置是這樣的:

的config.php

$config['upload_path'] = 'tmp/'; 
$config['allowed_types'] = 'zip'; 
$config['file_name'] = ''; 
$config['max_size'] = ''; 
$config['encrypt_name'] = false; 
$config['remove_spaces'] = true; 

控制器

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

我想繞過$配置的重新定義['測試] = $ this-> config-> item('test');

這是不可能的嗎?

回答

0

我不確定如果我錯過了某些東西,但根本不要將這些行放入控制器中。這實際上不會重新聲明它?

+0

又如何從$ this-> load-> library('upload',WHAT NOW HERE)中的配置加載聲明; – Ivan 2013-04-22 14:48:41

+0

您只需調用配置文件upload.php並將其放入您的配置文件夾。上傳類將自動加載在這個自定義文件中聲明的配置項。無需初始化它。看到這裏:http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html,搜索「在配置文件中設置首選項」 – 2013-04-22 15:02:28

+0

是的,但在設置首選項中,他定義$ config數組在一個文件中。但我的配置數據存儲在其他文件/config/upload.php我試着說你不工作 – Ivan 2013-04-22 15:10:37

0

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

+0

男人我在我的建設者,我不把所有的代碼bcs是大。 // Load config $ this-> load-> config('extension',FALSE,TRUE); – Ivan 2013-04-22 14:52:55

+0

我不知道你的意思? '$ this-> config-> load('custom_upload_settings',FALSE,TRUE);'會加載一個你需要創建的新文件(所以它應該是空的,直到你添加了'set_item()'行)。 – Justin 2013-04-22 14:55:57

+0

是啊,你不知道我的意思。我的問題是不是在配置和加載配置...我的問題是上傳庫如何從我的自定義配置捕捉設置,而無需再次定義。 – Ivan 2013-04-22 15:05:47

相關問題