• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Email library won't load

#1
[eluser]thedust2010[/eluser]
This is our 3rd or 4th CodeIgniter site and we haven't had issues up until now...

In /system/application/controllers/contact.php, we have:

Code:
class Contact extends Controller {
    
    function index()
    {
        $this->load->library('email');
        print_r($this->email); exit;
    }
}

This bit of code is not adding the email class to the CodeIgniter object. Pulling up the contact page brings up the following error:

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Contact::$email
Filename: controllers/contact.php
Line Number: 21

I've troubleshooted this all morning and I can determine that the "email" class is being initiated correctly in _ci_init_class (function returns true). But then it seems to lose scope. The class has only been added to the CodeIgniter object inside of _ci_init_class, but not outside. Any ideas? I've upgraded from 1.6.1 to 1.6.2 and no luck... thinking we may just use PHPMailer. I've also noticed that nothing is getting logged when I set it up to do so. Any help or opinions are much appreciated. Thanks in advance.

#2
[eluser]johnwbaxter[/eluser]
Posted the wrong bit of code in there sorry!

Have you got this running locally? I presume it's not a permission issue for writing the logs?

#3
[eluser]thedust2010[/eluser]
Your original suggestion worked great. Adding this did the trick:

Code:
function Contact()
    {
        parent::Controller();
        $this->load->library('email');
    }

So I take it we should always be loading libraries from the controller constructor?

#4
[eluser]freshface[/eluser]
or autoload.

I load them when necessary, I dont always need the mail lib.

#5
[eluser]johnwbaxter[/eluser]
Huh? I didn't mean to post that first bit of code, i used it to test it on my own server to see if i could replicate your issue. Did it work for you then?

It worked for me...

#6
[eluser]thedust2010[/eluser]
This was not working:

Code:
class Contact extends Controller {
    
    function index()
    {
        $this->load->library('email');
        print_r($this->email); exit;
    }
}

But this is working:

Code:
class Contact extends Controller {
    
    function Contact()
    {
        parent::Controller();
        $this->load->library('email');
    }

    function index()
    {
        print_r($this->email); exit;
    }
}

#7
[eluser]johnwbaxter[/eluser]
This should also work in theory:

Code:
class Contact extends Controller {
    
    function Contact()
    {
        parent::Controller();
        
    }

    function index()
    {
        $this->load->library('email');
        print_r($this->email); exit;
    }
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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