Welcome Guest, Not a member yet? Register   Sign In
Creating a Library
#1

[eluser]Karlos23[/eluser]
I am currently creating a library (Login_Auth) and I have hit a brick wall. I keep getting the same old error each time!
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: Forgot_pass::$email
Filename: libraries/Login_auth.php
Line Number: 144
Fatal error: Call to a member function from() on a non-object in /home/sniko/public_html/YouLoveMe/application/libraries/Login_auth.php on line 144
I don't see where I have gone wrong though, my code is currently and yes I have got the instance CI loaded via my __construct() function.
Code:
public function __construct()
    {
        $this->CI =& get_instance();
        
        log_message('debug', 'Login & Auth Class Initialized');
    }

Now the function.
Code:
public function forgot_pass($user_email)
    {
        if ($user_email == '')
        {
            return false;
        }
        
        if (!$this->CI->config->load('email'))
        {
            $this->CI->email->initialize($this->email);
        }
        
        $this->CI->email->from($email['name'], $email['address']);
        $this->CI->email->to($user_email);
        $this->CI->email->subject('Forgotten Password');
        $this->CI->email->message('');
        
        
        if ($this->CI->email->send())
        {
            return true;
        }
        
        return false;
    }

Any help? Thanks
#2

[eluser]Jelmer[/eluser]
Code:
$this->CI->email->from($email['name'], $email['address']);
Is the line on which it crashes. Presumably the system succeeds in loading the config file (which is why initialize() wasn't called) and only discovers at this line that the email class hasn't been loaded. You need to load the email class.
Code:
$this->CI->load->library('email');

if (!$this->CI->config->load('email'))
{
    $this->CI->email->initialize($this->email);
}

Also testing for a loaded config in this way is kinda useless as it will result in an error and the test will be of no use. If you want to test it you have to use it like this (read the User Guide if you don't know why):
Code:
if (!$this->CI->config->load('email', FALSE, TRUE))
{
    $this->CI->email->initialize($this->email);
}
#3

[eluser]Karlos23[/eluser]
Ahh I see my error now, thank you.
#4

[eluser]Karlos23[/eluser]
Seems I have ran into another problem, apparently it cannot load the database library but it hasn't been moved! I can autoload it without a problem but it won't let me load it through my library?

My __construct() function where I load it is:

Code:
public function __construct()
    {
        $this->CI =& get_instance();
        
        $libs = array(
            'email',
            'database',
            'session'
        );
        $this->CI->load->library($libs);
        
        log_message('debug', 'Login & Auth Class Initialized');
    }
#5

[eluser]Jelmer[/eluser]
What kind of error are you getting?

At a glance there's nothing wrong with the code but I (nor anybody for that matter) can't help you if you don't post your error with the code.
#6

[eluser]Karlos23[/eluser]
As I basically said, it is just saying it cannot load the database...
Quote:An Error Was Encountered
Unable to load the requested class: database
#7

[eluser]Jelmer[/eluser]
The problem is that the database isn't loaded like a library when loaded from the controller instead of the autoloader. Check the user guide on how to: http://ellislab.com/codeigniter/user-gui...cting.html
#8

[eluser]Karlos23[/eluser]
Ahh I see now, no wonder I didn't work. Thanks again for the help Jelmer!




Theme © iAndrew 2016 - Forum software by © MyBB