J'ai ce problème avec Codeigniter HMVC. Lorsque je veux charger une bibliothèque comme 'upload' ou 'image_lib', l'instance est toujours nulle si je la charge dans une fonction locale dans une classe. Cependant, lorsque j'instancie un objet dans un constructeur, la charge est réussie et je peux appeler des fonctions pour la classe de bibliothèque.Codeigniter HMVC - Impossible de charger une bibliothèque dans une fonction
Voici le code:
<?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
}
}
}
Ce sera génial si quelqu'un peut aider à ce problème.