CodeIgniter Forums

Full Version: Load more than one instance of the same library
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

How would I load more than one instance of the same library?

I have this:

$this->load->library('SelectQuery', array('table' => 'items'));

   # Must have categories with images and a parent
   JOIN categories_items
      ON = categories_items.item_id
   JOIN categories
      ON (
         categories_items.category_id =
         AND categories.in_nav != 0

   # Must have an artist
   JOIN artists
      ON items.artist_id =

   # Must have at least one image
   JOIN item_images
      ON item_images.item_id =
$this->selectquery->addWheres(" != 0
   AND items.quantity > 0
   items.title ASC, ASC
   CEILING(100 - items.sale_price/items.price*100) AS percent_off

It seems like once the $this->selectquery variable is used once, it can't be used again without being overwritten.

El Forum

[eluser]Pascal Kriete[/eluser]
CI includes the class, does some stuff, instantiates it, and stores that object reference in an array. What you get when you say $this->load is that reference. That's done so that you don't actually overwrite the instance when you use it in say a controller and later on in another library.

The easiest thing to do is to just make a new one. Remember, it's already included so all you do is:
$bla = new Name();

Alternatively you could add some sort of restore function to your class that you call to reset all class variables. That way you keep the CI benefits and get to reuse it. That doesn't work if you need multiple instances simultaneously, of course.

El Forum

Thanks again, inparo.

El Forum

[eluser]Pascal Kriete[/eluser]
My pleasure Smile .