0
我遇到了Codeigniter HMVC的這個問題。Codeigniter HMVC - 無法在函數中加載函數庫
當我想加載一個庫,例如'upload'或 'image_lib'時,如果我將它加載到類的本地函數中,該實例始終爲空。但是,當我在構造函數中實例化對象時,加載成功,我可以調用庫類的函數。
下面的代碼:
<?php
class Listed_items extends MX_Controller {
function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->library('upload'); // this works
$this->load->library('image_lib'); // this works
$this->form_validation->set_ci($this);
}
function do_upload($item_url) {
$submit = $this->input->post('submit', true);
if ($submit == "cancel") {
redirect('listed_items/create_item/'.$item_url);
} else if ($submit == "upload") {
$config['upload_path'] = './big_pics/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 300;
$config['max_width'] = 3036;
$config['max_height'] = 1902;
$file_name = $this->site_security->generate_random_string(16);
$config['file_name'] = $file_name;
$this->load->library('upload', $config); // this calls on null
}
}
}
這將是真棒,如果有人可以幫助解決這個問題。