• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using functions from My_library in controller

#1
[eluser]Unknown[/eluser]
Hi,

I've created my own custom library (application/libraries/MY_Send_email.php) which extends CI_email. I did this as I will be using email functionality a lot in my website. So far within this class I have a function named sendActivation. How do I call this function from my controller? Below I have my class code and below it my controller code. Any help would be awesome. Thanks!

Here is the error I get.
Severity: Notice

Message: Undefined property: MY_Send_email::$email

Filename: libraries/MY_Send_email.php

Line Number: 19

Fatal error: Call to a member function from() on a non-object in C:\wamp\...\application\libraries\MY_Send_email.php on line 19

//LIBRARY
class MY_Send_email extends CI_Email {
function __construct() {
$CI =& get_instance();
parent::CI_Email();
}

function sendActivation(){
line 19 $this->email->from('[email protected]', 'hi');
}
}

//CONTROLLER
function __construct()
{
parent::Controller();
$this->load->library('email');
$this->load->library('MY_Send_email');
}

function whatever(){
$this->my_send_email->sendActivation(); //this is where I get the error
}

#2
[eluser]WanWizard[/eluser]
If you extend a core class, it needs to me named properly. In this case, MY_Email. CI will automatically load it when you load the email lbrary.

See the user guide on extending core classes.

#3
[eluser]Unknown[/eluser]
Thanks a lot. I will give this a try. Looks like I was making it way harder than it needed to be.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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