[eluser]Myles Wakeham[/eluser]
I'm hoping some kind soul can shed some light on how I can do this... Here's the background:
I am developing an 'email template' system. Basically its like a CI View or Smarty type templating engine, but its for email content. The user can create a template for the body of an email, something like this (this is a 'Forgot password' email example):
"We received your request. Your password is {user->password}"
I need to replace the stuff in the { } tags. Since this will be used for hundreds of different purposes, the models that are referenced will be many and varied. My current application has about 30 models in it, and I'll expose certain properties for this as needed.
I have written some functions to extract all the tags from the template source. That's working fine. I have an array of these tags ready for processing.
The problem is now how I can replace the tags with the current instance of the class/property that the tag is referring to. In my case, I'm using a direct reference to the model/property that is loaded in the controller that calls the class, and I have an object created from that controller and loaded with the data that I want to use for the template. The function gains access to the object created in the controller through:
Code:
$contr = & get_instance();
$the_user = $contr->user;
(this is just one example for a user model)
I have a property in this example class called 'password' that I can generally reference as $the_user->password. Works fine in regular functions. But in my case I want the reference to it to be variable (based on the tags found in the template).
So how do you reference an object (model) property this way?
I've tried the following which don't work:
Code:
$source_data = 'user->password';
echo ${$source_data};
or
Code:
echo & ${$source_data};
but that doesn't work. I've also tried doing this with an eval statement, but I get the exact same problem.
What's the best way to reference a model's object and its properties from a plug-in function?
Myles