I have a library in CodeIgniter called “someclass”.
class someclass extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('email');
$this->load->database();
// $this->load-> library('database');
}
function email($naar=0,$onderwerp=0,$bericht=0){
if ($naar > 0 && $naar<10) {
$to = "tester@test.com"
//this is the part where it goes wrong
$CI =& get_instance();
$this->load->library('email');
//some one said that i needed ti assign the library's
$this->_assign_libraries();
$this->email->from('tester@test.com', 'test');
$this->email->to($to);
$this->email->subject($onderwerp);
$this->email->message("Test
bericht :
".$bericht);
$this->email->send();
// echo $this->email-> print_debugger();
}
}
}
I get the following error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: someclass::$email
Filename: libraries/someclass.php
Line Number: 139
You can have 2 situations in my vision.
Here, you can create a method called sendEmail
Load your custom library in your controller and call id with
sendEmail(....)You can extend native email library class and create a method inside that class called sendEmail for example:
class MY_Email extends CI_Email {
public function _construct()
{
parent::_construct();
}
public function sendEmail () ….. etc.
}
From your controller load native library class, use
$this->load->library('email')and send your email by calling$this->email->sendEmail(...)