CodeIgniter Forums

Full Version: How to include pre-written libraries?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jahboite[/eluser]
Hello!

Bit of background:
I'm developing an application for facebook. Before attempting this, I'd never written any php and I'm not completely au fait with javascript. I started development on my app from scratch using notepad (well Textpad actually, but manually is what I mean) and then I found out that other people were using php frameworks like drupal and CodeIgnitor. I couldn't believe I'd missed such a thing.

Yesterday I decided to get hold of CI and started learning about it, playing with it and started to recreate my application using it. It looks like a great bit of kit and I was hooked once I'd watched the tutorial vids.

Facebook provides some php classes and I needed to work out how to use these with CI. At first, I just php included them, but was getting some undefined index notices. Did a bit of research and decided to load the facebook classes as plugins. This seems to have worked nicely and CI stopped complaining about the index.

Then I was reading about CI libraries and I thought I'd have a go at loading the facebook classes as libraries instead. I had to capitalise the filenames, and I also separated an existing php file into two separate php files, one for each of two classes, naming the files the same as the contained class...

Trouble was CI started warning me about missing arguments for the functions as they were instantiated. I played and fiddled, but realised I was fumbling around in the dark so I went back to loading as plugins.

My question is, given an external library, what's the proper way to use them within CI such that one doesn't have to rewrite them or make major mods?

El Forum

[eluser]Matthew Pennell[/eluser]
If a third-party library has a decent API, they should just work if you drop them into the /libraries folder. Possibly splitting a class up might have caused a problem.

Are you using PHP5? I know the Facebook REST library class has some weird echoed JavaScript in the middle of it that might cause a problem too.

El Forum

[eluser]jahboite[/eluser]
When you say drop them into libraries, do you mean I should load them as libraries or just dump them in libraries and php include them?

I didn't exactly split a class up, I split a file into two because it contained two classes and the documentation says that the filename should be the same as the classname

I'm using php 4 (well my hosted box is php 4). The rest lib does have some javascript, but that didn't seem to be an issue...