• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading DB Class in Helpers

#1
[eluser]pmonty[/eluser]
I am sure this is as obvious as the nose on my face, but how do I implement loading the DB class in a helper function?

Paul

#2
[eluser]Référencement Google[/eluser]
$CI =& get_instance();
$CI->load->model('your_model');

#3
[eluser]tonanbarbarian[/eluser]
Utilizing CodeIgniter Resources within Your Library
works for helpers and plugins as well

#4
[eluser]pmonty[/eluser]
Thanks, all. That is exactly what I was looking for.

Paul

#5
[eluser]pmonty[/eluser]
Well, trying to implement this, I am still having some problems. Here is my code.

Code:
CI =& get_instance();
$params = array('default', TRUE);
$DB1 = $CI->load->library('database',$params);

Can anyone see why this returns the PHP Error
Quote:An Error Was Encountered
Unable to load the requested class: database

Paul

#6
[eluser]xwero[/eluser]
no dollar sign on the first line Smile

#7
[eluser]pmonty[/eluser]
Just a typo in the post. It is there in my code but generating the error as noted.

Corrected and as in my helper code:

Code:
$CI =& get_instance();
$params = array('default', TRUE);
$DB1 = $CI->load->library('database',$params);

Paul

#8
[eluser]xwero[/eluser]
The database class isn't loaded as a library, it has its own load method
Code:
$CI->load->database(); // loads default group
$CI->db->query(); // example use methods first loading possibility
$DB1 = $CI->load->database('default',true); // loads default group as an independent object
$DB1->query(); // example use methods second loading possibility

I think you mixed up a few things in your snippet

#9
[eluser]pmonty[/eluser]
Yup, Thanks Xwero.

I was confusing sample language from the docs with how to actually implement the call. Your examples did it.

Thanks again.

paul


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.