Welcome Guest, Not a member yet? Register   Sign In
Custom library question, for clarification?
#1

[eluser]whygod[/eluser]
Hi

I just want to clarify my understanding.
Okay the User Manual says, to utilize CodeIgniter Resources within a Library.
I need to do it like this below,

Code:
$CI =& get_instance();

$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');

So meaning when extending the MY_Controller below is not right?
MY_Controller:
Code:
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller
{
public $data = array();

    function __construct ()
    {
        parent::__construct();
  
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('form_validation');  
        $this->load->library('jaz_lib');
    }
}

Custom library: Jaz_lib.php
Code:
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');

class Jaz_lib extends MY_Controller
{
public $data = array(
                   '' => '',
    );

    function __construct ()
    {
        parent::__construct();
  
        
    }


public function logout()
{
  //Destroy session
  $this->session->sess_destroy();
  
  //Delete coockie

  return TRUE;  
}
    
}

Meaning the classes that was loaded in the MY_Controller,
will not be inherited in Jaz_lib library?

Thanks in advanced.

#2

[eluser]whygod[/eluser]
Also is it necessary to include a __constructor in a custom library?
Or no need anymore?
#3

[eluser]LuckyFella73[/eluser]
In Codeigniter libraries are standalone classes - they don't
extend any controller class!

For the constructor question: you don't have to set it up in general
but you need it if you want to pass arguments when loading the library.

##
EDIT: or if you want to run some code when the class is instantiated.
##

See userguide:
http://ellislab.com/codeigniter/user-gui...aries.html




Theme © iAndrew 2016 - Forum software by © MyBB