[eluser]JayTee[/eluser]
I'm trying to implement an emailing "system" of sorts - basically, I'm abstracting the email library with my own. Here's what I'm doing:
- I'm have a series of about 50 editable email "templates" stored in the database
- Each template has placeholders that are substituted for values when the email is sent
- I want to be able to use a generic means to say:
Code:
$this->emailModel->trigger('template_name',$somedata);
I don't want to bore you with the details, but the gist of the matter is this: The code for *parsing* the email templates is the same - but the placeholders are different for each email. I want to be able to have common code such that:
Code:
$this->emailModel->trigger($template_name,$data);
will be able to handle all the different templates - with only the $data variable (an array) containing different information that's specific to the email template.
(I hope I've made sense in my description.)
There's more than one way to skin a cat, "they" say, so here was my first shot:
Controller:
Code:
$this->load->model('emailmodel');
$this->emailmodel->trigger('email_template_name',$data);
email_template_name model:
Code:
class email_template_name extends Model {
function __construct() {
parent::Model();
}
function loadEmailData() {
//do stuff
}
}
emailmodel:
Code:
function trigger($template_name,$data) {
$this->load->model($template_name);
$this->$template_name->loadEmailData($data);
$this->sendEmailTemplate($this->$template_name);
}
As you can guess, I get an error when I try to execute the code in the email model. It won't let me call the "loadEmailData" method of the object.
The weird thing is if I put a show_error in the constructor of the email_template_name model, it shows up; so I know the model is actually getting loaded.
So.....
Is there any way I can use a variable as the object? ($this->$objectname->method()). I can get this to work in "straight PHP", but it doesn't seem to work in CI; or maybe I'm missing something?