Welcome Guest, Not a member yet? Register   Sign In
Can I load a Library from within a Helper?
#1

[eluser]kimp[/eluser]
Hi,

I have a function which loads the email library then goes on to send an email.

Since I need the function to be available from a few places, I want to put it in a helper.

The code works fine when it's in a controller, but throws an error when I put it in a helper.

Should I be able to load a library from within a helper? What about when I'm extending a native helper (i.e. MY_email_helper)?

Thanks!
#2

[eluser]jmadsen[/eluser]
try:

Code:
$CI =& get_instance();
$this->CI->load->library('my_lib');
#3

[eluser]Dennis Rasmussen[/eluser]
[quote author="kimp" date="1286893407"]Should I be able to load a library from within a helper?[/quote]

Yes, but it's not a good thing to do.
Instead just create a library extending the mail library having your neat function within.
#4

[eluser]kimp[/eluser]
Hi,

You blokes a legends.

>> jmadsen -> I haven't tried your solution, but I'm sure it would work. I found an example of it in one of the system helpers.

>> Dennis -> Thanks for the 'best practice'. I'll give it a try.

Kim




Theme © iAndrew 2016 - Forum software by © MyBB