views:

73

answers:

3

Hello all,

I have found a class I would like to use to get bookmarks from a users delicious account. Here is how it is used.

The problem I am having is, should I be turning this into a Codeigniter library? Can I not use it on its own as this is self contained? I am guessing I am asking for the best practice here.

Thanks all for any help

A: 

Hi,

Just add that code has one Helper, and use the functions you want.

in your system/application/helpers

create one file my_helper.php and paste your code in http://www.ejeliot.com/samples/delicious-backup/backup-to-mysql.txt, don't forget to put the code inside one function X.

in the you controller:

$this->load->helper('my_helper');

and then

you can call you function X() in you controller and use you magic code!

Regards,
Pedro

Pedro
What do you mean? Can you elaborate please.
Abs
I made one improvement in my reply, please take one look
Pedro
A: 

Can I not use it on its own as it is self contained?

I think not unless that class is made as per the requirements of CodeIgniter. Any class that you want to add to CodeIgniter's library should have all that is required by a CodeIgniter library, for example, you should pass arguments as array to the constructor of each library.

See: Creating Your Own Libraries as a guide on how to incorporate your classes in CodeIgniter.

Sarfraz
@Sarfraz I know that I can not use this as a library unless I follow all the CI guidelines. My question is, can I use a normal PHP class within my CI web app or do I have to turn this PHP class into a CI library, helper, model etc...
Abs
A: 

Since the code is all self-contained (it looks like) - just wrap the whole thing (except the php tags) in function within class Delicious{} - like so:

class Delicious {

  function doBookmarks(){

      [insert all library code here]

    }
}

Then load the library and where you want the data, call $bookmarks = $this->delicious->dobookmarks.

Make sure to refer to the CI Library link above to make sure your code is nested properly, or it won't load correctly - and remember that you need to get_instance() inside the library code if you want to call back to any of the CI code - which you should do as little as possible outside CI, since it causes memory issues.

b. e. hollenbeck