Loading multiple libraries in CodeIgniter - PHP

I need to load more than 2 libraries in the CI controller and call their member functions. I tried the following methods, but did not use.

1.

    $this->load->library('liba');
    $result = $this->liba->SearchTours($searchParams);
    echo $result;

    $this->load->library('libb');
    $result2 = $this->libb->tourFetch($searchParams);
    echo $result2;

2.

    $this->load->library(array('liba' , 'libb'));

    $result = $this->liba->SearchTours($searchParams);
    echo $result;
    $result2 = $this->libb->tourFetch($searchParams);
    echo $result2;

3.

    $this->load->library('liba');
    $this->load->library('libb');

    $result = $this->liba->SearchTours($searchParams);
    echo $result;
    $result2 = $this->libb->tourFetch($searchParams);
    echo $result2;

4.

    public function __construct(){
      parent::__construct();
      $this->load->library('liba');
      $this->load->library('libb');
    }
  1. I changed the boot order in 4 cases. Whatever is mentioned, the second one does not load.

In all cases, only the first library mentioned is loaded, and this notification is displayed for the second.

A PHP Error was encountered Severity: Notice Message: Undefined property: Unify::$libb Filename: controllers/Unify.php Line Number: 30

I could not find a single soul in the CI or SO user guide. What am I doing wrong?

+4
source share
3 answers

whenever you use libraries and helpers and you need a built-in method from CI, use

$CI =& get_instance();

and then use it like that

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

. codeigniter.com/userguide2/general/creating_libraries.html


codeigniter + HMVC, , .

MVC vs HMVC -

!

+1

CI

$this->load->library( array('liba', 'libb') );

,

$CI =& get_instance(); 

+2

. , , , , . :

myController extends CI_Controller{}

else $CI =& get_instance();

$CI->load->library('your_library');

Edit: . , inoyur, Libb.php

+2

All Articles