Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code igniter third party, $this->load->add_package_path not working correctly

I am trying to use elliothaughins Socialize system for code igniter,

However I keep getting

Message: include(application/third_party/config/socializenetworks.php): failed to open stream: No such file or directory

I have traced this issue and when I call
$this->load->add_package_path(APPPATH.'third_party/socialize/');

In the loader class if I do die($path) I only get application/third_party.

It seems strange though as the code for the controller is

class SocializeController extends CI_Controller {

  function __construct(){
    parent::__construct();
    parse_str($_SERVER['QUERY_STRING'], $_GET);
    $this->load->add_package_path(APPPATH.'third_party/socialize/');
    $this->_autoload();
  }

  private function _autoload(){
    $this->load->model('socialize_migration_model');
    $autoload = array();

    include(APPPATH.'third_party/socialize/config/autoload'.EXT);
    foreach ( $autoload as $type => $files ) {
      $type = ($type == 'libraries') ? 'library' : $type;

      foreach ( $files as $file ){
        $this->load->$type($file);
      }
    }
  }

  public function data($key, $value)
  {
    $this->load->vars(array($key => $value));
  }
}

Which as you can see it is calling a model, which it successfully loads, It is when It gets to the autoloader where it loads the libraries where it breaks,

The particular library that is giving issue starts like

class SocializeNetworks {

  private $_obj;
  private $_networks = array();

  function __construct(){
    $this->_obj =& get_instance();
    $this->_obj->load->config('socializenetworks'); // this is the line we die on :(

So,

Whats going on here and how can I fix it?

like image 742
Hailwood Avatar asked May 30 '11 01:05

Hailwood


1 Answers

I traced this down to a bug just yesterday in the CI v2.0.2 code base. Essentially what is happening is you are adding an additional path to check for files in (which is correct) and the load method loops through each of the paths until it finds the file you are looking for.

If you output your CI object, you'll probably see that what you are looking for is there, but it's still failing.

In the file /codeigniter/core/Config.php where the load method is, for some reason, the $found=false; isn't reset on each iteration through the path loop, so if the path is found on the first run (as it was in my case) then $found is set to true, but then on subsequent runs, $found is still true, so it tries to include a non-existent file.

I solved this by moving the declaration for the $found variable to just below the start of the first foreach loop. This way it resets it each time. I reported the bug, so hopefully it will be addressed in subsequent versions.

like image 148
muely2k1 Avatar answered Sep 24 '22 14:09

muely2k1