Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include external Libraries in CodeIgniter?

Tags:

I'm new to codeigniter, and I'm trying to integrate amazon's FPS into my page. There are a bunch of libraries and models that go with Amazon FPS, which I would need included to make the appropriate calls.

How do I include them in CodeIgniter?

I tried placing the entire Amazon folder inside the system/libraries directory, and then tried including libraries with $this->load->library( 'Amazon/FPS/Client' ); However, I run into problems with the relative path there, because Client.php contains the statement require_once ('Amazon/FPS/Interface.php'); ... which is in the same folder.

There has to be a better way to do all this - can anyone please help?

Thanks!!

like image 796
itwasthewind Avatar asked Feb 25 '10 20:02

itwasthewind


People also ask

HOW include external library in CodeIgniter?

php the library you need to add this below code in the controller. $this->load->library ( 'getID3/getid3/getid3', '', 'getid3(you can add any name you want' ); Now to Use this: $this->getid3->your_function($data);

Where do I put library in CodeIgniter?

All of the available libraries are located in your system/libraries/ directory. In most cases, to use one of these classes involves initializing it within a controller using the following initialization method: $this->load->library('class_name');

Can you extend native libraries in CodeIgniter?

As an added bonus, CodeIgniter permits your libraries to extend native classes if you simply need to add some functionality to an existing library. Or you can even replace native libraries just by placing identically named versions in your application/libraries directory.

What is third party in CodeIgniter?

To segment these third party libraries with your own libraries, CodeIgniter has brought a new segmented folder i.e. third party folder. So, if you are using CodeIgniter then you have to put that third party API libraries within the same library folder where you have kept or created your own application libraries.


2 Answers

There is nothing stopping you from directly including classes and working with them however you would in a vanilla PHP setup. If it works in PHP it will work in CodeIgniter.

include(APPPATH.'libraries/Amazon/FPS/Interface.php'); 
like image 105
Phil Sturgeon Avatar answered Oct 03 '22 07:10

Phil Sturgeon


Peng Kong of a3m http://code.google.com/p/a3m/ has a nice way of doing it with plugins:

Example twitter_pi.php

require_once(APPPATH.'modules/account/plugins/libraries/jmathai-twitter-async/EpiCurl.php'); require_once(APPPATH.'modules/account/plugins/libraries/jmathai-twitter-async/EpiOAuth.php'); require_once(APPPATH.'modules/account/plugins/libraries/jmathai-twitter-async/EpiTwitter.php');

/* End of file twitter_pi.php / / Location: ./system/application/modules/account/plugins/twitter_pi.php */

In controller

$this->load->plugin('twitter'); $twitterObj = new EpiTwitter($this->config->item('twitter_consumer_key'), $this->config->item('twitter_consumer_secret'));

There is one problem with this in Codeigniter 2.0 there are no plugins

like image 20
Dave Avatar answered Oct 03 '22 06:10

Dave