0

I am using codeigniter 3.1.2

I want to separate email methods into a separate file of its own, and call on them as needed. Much like how one can call methods in a model from controller with $this->Some_model->some_method();

From my understanding, it would be best to do this via libraries?

But I am having trouble understanding how to set it up.

Below is my attempt to make it work

In my controller I have

 $this->load->library('CustomEmail');
 $result = $this->CustomEmail->email_reciept($emailaddress,$orderinfo);

In my application/library folder I have a file called CustomEmail.php. In that file is

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class CustomEmail {

        public function email_receipt($emailaddress,$orderinfo){
          //codes related to config, prepare and sending email message
          //the code can email properly if I use it directly in controller
          //but I want to avoid repeating this code in every place I want to send email
        }
}
u_mulder
  • 54,101
  • 5
  • 48
  • 64
codenoob
  • 539
  • 1
  • 9
  • 26
  • 1
    Please read this http://stackoverflow.com/questions/804399/codeigniter-create-new-helper – u_mulder Dec 02 '16 at 21:34
  • ok this worked, using helper instead – codenoob Dec 02 '16 at 22:06
  • 1
    This is OP. for those seeking same answer, please refer to this http://stackoverflow.com/questions/9311878/code-igniter-load-send-email-in-a-library – codenoob Dec 02 '16 at 22:06
  • Note your class should be like `class Customemail {` not `class CustomEmail {` and file name Customemail.php –  Dec 02 '16 at 22:10

0 Answers0