->bufferedOutputObject() -- Merges a controller object with the template and returns the result
Description
This maps the values of the supplied object and runs the compiled template,
and returns the result.
This can be used in conjuction with PEAR::Cache, or in the example below, with
a email template (note this still needs testing.. - the backend should
eventually support a native tokenizer for email templates.)
Return value
string - the object variables overlayed on the template
Note
This function can not be called statically
Example
Example 25-1. Person DataObject send_password method class DataObjects_Person {
var $id;
var $name;
var $password;
var $cleartextPassword;
var $email;
function send_password() {
$this->generatePassword();
$template = new HTML_Template_Flexy();
$template->compile("Emails/Send_Password.txt");
$mailtext = $template->bufferedOutputObject($this);
$decoder = new Mail_mimeDecode($mailtext);
$parts = $decoder->getSendArray();
if (PEAR::isError($parts)) {
echo "PROBLEM: {$parts->message}";
exit;
}
list($recipents,$headers,$body) = $parts;
$mail = Mail::factory("SMTP",$options);
$mail->send($recipents,$headers,$body);
}
} |
|
Example 25-2. An email template From: "HTML_Template_Flexy" <html_template_flexy@pear.php.net>
Sender: "HTML_Template_Flexy" <html_template_flexy@pear.php.net>
To: {email}
Subject: Here is your new password
Content-Type: text/plain; charset=us-ascii
Dear {name}
Your New Password is {cleartextPassword}
please use it to log into your bank account :) |
|
Example 25-3. The resulting email head and body From: "HTML_Template_Flexy" <html_template_flexy@pear.php.net>
Sender: "HTML_Template_Flexy" <html_template_flexy@pear.php.net>
To: demo@example.com
Subject: Here is your new password
Content-Type: text/plain; charset=us-ascii
Dear Fred Blobs
Your New Password is 0ab123dcc
please use it to log into your bank account :) |
|