views:

38

answers:

2

Hi,

I'm still learning my way around PHP and CodeIgniter, but I'm trying to set up an email controller. The only problem is that most tutorials show how to set up the email.php controller, but hardcode the email address and message.

In the project I'm working on, I will be sending emails for many things (registration, password reset, etc...).

How could I set up the email controller to accept parameters and how would I load it from another controller?

Thanks!

+2  A: 

An email controller? I suppose you want a controller that can send emails right? If yes, you can use the email library (http://codeigniter.com/user_guide/libraries/email.html) CI provides in your controller.

Aman Kumar Jain
+1  A: 

You do not want to make it a controller. You should create this as a library. Then you would load the library when needed. You could pass values to the email library from the url of the calling controller

read these pages

http://codeigniter.com/user_guide/general/creating_libraries.html

http://codeigniter.com/user_guide/general/controllers.html#passinguri

http://codeigniter.com/user_guide/general/controllers.html#private

The structure of CI is a bit specific and the closer you stick to it the more you will love it.

libraries are your functions

controllers construct views using data from the url models and your libraries

views display your constructed data

/////////emaillibrary.php

class email {

function email{
}

function do_some_stuff($spoon){
/////// dance
}
}

//// email controller

class emailcontroller extends Controller{

function sendMail($spoon){ /* <------ this is going to pass any info in the url down into your controller so if some one does www.myite.com/index.php/emailcontroller/sendmail/car  $spoon will equal car
$this->load->library('email'); */

$this->email->do_some_stuff($spoon);
}


}

Also if you need a function that is specific to your controller and of no use any where else instead of a library you would create a function with an underscore

and as a completly off topic piece of advice when you get to making DB calls, make use of models no matter how simple the DB call is. I assure you you will come find me to hug.

Doodle