cannot load 'image_lib'

In my advanced module I created a library file called: Createthumbs.php. It contains the following code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Createthumbs extends CI_Controller { function __construct() { parent::__construct(); // load all the helpers we need $this->load->helper('convert'); $this->load->helper('ajax'); $this->load->helper('cookie'); $this->load->helper('inflector'); $this->load->helper('text'); $this->load->library('image_lib'); } }

but when I load this library in my view I get the error message:

A PHP Error was encountered Severity: Notice Message: Undefined property: Dennie::$image_lib Filename: fuel/Loader.php Line Number: 215

Why could this be?

Comments

  • edited 5:33PM
    How are you accessing it in your view? Are you using the object "$this" or the object "$CI". They both represent the same thing but "$CI" is probably what is available for you.
  • edited 5:33PM
    I was using the $this object. The $CI object (after assigning it to get_intance) gives the same error. Here is my code in the view:

    <?php $CI =& get_instance(); $CI->load->library('createthumbs') ?>

    or

    <?php $this->load->library('createthumbs') ; ?>

    For example loading the library in the view works fine:

    $this->load->library('image_lib');
  • edited 5:33PM
    By the way. Like in the Fuel_base_controller, this works:
    $this->load->library('form');
  • edited 5:33PM
    Is $image_lib referenced in createthumbs? If so, are you using $CI =& get_instance(); in the createthumbs library?
  • edited 5:33PM
    Yes it is referenced. I used both $this and $CI=& get_instance(). Both did not work.
    I solved my problem by not extending the CI_Controller but by just making a class:
    class Createthumb { public function __construct( $params = array() ) { $this->CI =& get_instance(); if (count($params) > 0) { $this->initialize($params); } $this->CI->load->library('image_lib'); } function initialize($config = array()) { foreach ($config as $key => $val) { if (isset($this->$key)) { $this->$key = $val; } } } function makethumb( $img, $width, $heigth ) { $fotonaam = basename($img); $fotonaam_no_extension = pathinfo($img, PATHINFO_FILENAME); $img_tumb_path = dirname($img) . '/thumbs/' . $fotonaam_no_extension . '_' . $width . '_' . $heigth . '.jpg' ; $img_source_path = $img . '/' . $fotonaam; // ChromePhp::log(MODULES_PATH); if (!file_exists($img_tumb_path)) { $config['image_library'] = 'gd2'; $config['source_image'] = $img_source_path; $config['width'] = $width; $config['height'] = $heigth; $config['new_image'] = $img_tumb_path; $this->CI->image_lib->initialize($config); if ( ! $this->CI->image_lib->resize()) { ChromePhp::log($this->CI->image_lib->display_errors()); } $this->CI->image_lib->clear(); } return dirname( $_SERVER['SCRIPT_NAME']) . '/' . $img_tumb_path; } }

    Thanks for all the feedback again.
    If anyone comes up with an idea I would still like to know what could be the problem.
  • edited April 2012
    Why did you want to extend the CI_Controller class? What you have working now looks correct to me.

    Anyway, I tried it and had no errors with:

    Createthumbs.php in /modules/my_module/libraries/
    class Createthumbs extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper('convert'); $this->load->helper('ajax'); $this->load->helper('cookie'); $this->load->helper('inflector'); $this->load->helper('text'); $this->load->library('image_lib'); echo 'loaded'; } }

    In a view in the adv. module:

    $this->load->module_library('my_module', 'createthumbs');

    No errors, just see 'loaded' on the screen.
  • edited 5:33PM
    Okay thanks. Will check it again with the module_library.
Sign In or Register to comment.