I have a library in CodeIgniter called \"someclass\".
class someclass extends CI_Controller {
function __construct() {
parent::__construct();
You can have 2 situations in my vision.
Here, you can create a method called sendEmail
function sendEmail($naar=0,$onderwerp=0,$bericht=0)
{
$CI =& get_instance();
$CI->load->library('email');
//or autoload it from /application/config/autoload.php
$CI->email->from('tester@test.com', 'test');
$CI->email->to($to);
$CI->email->subject($onderwerp);
$CI->email->message("Test
bericht :
".$bericht);
$CI->email->send();
}
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(...)
You're doing it all wrong! Are you trying to write your own library? Or are you trying to write a controller for a page?
If you're trying to write a controller, you don't need to run the get_instance()
function. Simply extends the CI_Controller
class, load the appropriate library, in this case it's email
, and use it according to the documentation. Also, controllers are to be put inside the controllers
folder.
But if you're trying to write a library, you can't extend from the CI_Controller
class. You'll also need to grab the instance of CodeIgniter using the get_instance()
function and store it in a variable. After that simply use the object to load the email
library and send the emails.
Also, I don't think you can call a method with an underscore prefix from that class. I'm talking about $this->_assign_libraries()
. In CodeIgniter, a method prefixed with an underscore is a private
function. Thus, you can't access it from within your own class. (Unless of course, it's a protected
function and you extend the class).