Welcome Guest, Not a member yet? Register   Sign In
Messing with OOP in Codeigniter
#2

[eluser]rjsmith[/eluser]
First, since you want to use CI resources in your library, you have to grab a reference to CI. For example, here's what I would do:
Code:
class FQGallery{
    private $CI;
    //Other member variables
    ...

    public function __construct($options){
        $this->CI =& get_instance();

        //Set member variables using $options array
        ...

        $this->CI->load->database();
        $this->CI->load->model('m_fqgallery');
        $this->CI->load->library(array('form_validation', 'session'));
    }

    ...
}

I would also return 'this' in my methods in case I wanted methods to be chainable.

Next, in the controller:
Code:
class Gallery extends CI_Controller{
    public function __construct(){
        parent::__construct();
        
        $options = array(
            'setting1' => 'value1',
            'setting2' => 'value2'
            ...
        );
        $this->load->library('fqgallery', $options, 'gallery'); //$this->gallery now refers to fqgallery
    }
}


Messages In This Thread
Messing with OOP in Codeigniter - by El Forum - 02-10-2013, 05:34 AM
Messing with OOP in Codeigniter - by El Forum - 02-10-2013, 12:38 PM
Messing with OOP in Codeigniter - by El Forum - 02-11-2013, 12:40 AM
Messing with OOP in Codeigniter - by El Forum - 02-11-2013, 05:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB