Welcome Guest, Not a member yet? Register   Sign In
Loading a library inside a helper
#1

[eluser]Freewolf[/eluser]
Can I load a library from inside a helper.
I am trying to do it and it does not seem to work, so wondering if I am doing something wrong.

Code:
if ( ! function_exists('send_thank_you'))
{
   function send_thank_you()
   {
        $CI =& get_instance(); // Get the global CI object
        $CI->load->library('email');

        $CI->email->from('[email protected]', 'testing');
        $CI->email->to('[email protected]');

        $CI->email->subject('Thanks.');
        $CI->email->message('Testing the email class.');

        $CI->email->send();

        echo $CI->email->print_debugger();
   }
}
#2

[eluser]Freewolf[/eluser]
Bumping this any suggestions from anyone?
#3

[eluser]Narkboy[/eluser]
From the user guide:

Quote:Unlike most other systems in CodeIgniter, Helpers are not written in an Object Oriented format. They are simple, procedural functions. Each helper function performs one specific task, with no dependence on other functions.

The easiest way to do this would be to drop the send_thank_you into a model or library then call it from there. I imagine you've got other email related functions? An email model may be the easiest way to go!

/B
#4

[eluser]cideveloper[/eluser]
This works for me. How are you calling the helper? Does your email work if you just have it in the controller?

application/helpers/new_help.php

Code:
function meow($result = '') {
    $CI =& get_instance();
    $CI->load->library(array('email'));
    $CI->email->from('[email protected]','Name');
    $CI->email->to('[email protected]');
    $CI->email->subject('testing');
    $CI->email->message('Works! damn it...');
    $CI->email->send();
    return $result . '<br />' . $CI->email->print_debugger();
}

Method in controller

Code:
function libinhelper() {
        $this->load->helper('new');
        echo meow('Does This Work');
    }




Theme © iAndrew 2016 - Forum software by © MyBB