Php – How to adapt a PHP library to Codeigniter

codeigniterPHP

Good mor(eve)ning guys. My question is a bit general:
How can I adapt any PHP library (like facebook sdk for example) to use in CodeIgniter?

Generally, when you download a PHP library and look to the examples provided, you load the library using include or require_once. What are the adjustments (and ways) to use $this->load->library($name, $params)?

And how can I use the library after that: replacing $var = new Library($data) by ???

If my question is not yet clear, please notify me.

(bonus question: How to apply this to facebook-sdk ?)

Thanks in advance.

Best Answer

  1. create a folder to place a facebook-sdk files in it: /application/libraries/facebook/
  2. create a Facebook_lib.php in the libraries root with the content:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    require_once 'facebook/facebook.php';
    class Facebook_lib extends Facebook{}

  3. in controller:

    $this->load->library('facebook_lib',$config); $this->facebook_lib->clearAllPersistentData();