Prev | Current Page 246 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

6 you can see the contents of that row class and how our save() method overrides the parent
class save() method and adds the notification email to the support team.
Listing 9.6: Overriding save() in our SupportTicket subclass to trigger email
class SupportTicket extends Zend_Db_Table_Row_Abstract
{
public function save()
{
parent::save(); A
$mail = new Zend_Mail(); B
$mail->setBodyText($this->body);
$mail->setFrom('system@example.com', 'The System');
$mail->addTo('support@example.com', 'Support Team');
$mail->setSubject(strtoupper($this->type) . ': ' . $this->title); C
$mail->send();
}
}
A Call the parent class save() method
B Instantiate Zend_Mail, set-up headers and send
Licensed to Menshu You
Zend Framework in Action (Ch010) Manning Publications Co. 9
Now, whenever a call is made to the save() method, an email will be sent to the support team with the
support ticket information in the body of the email.
It isn??™t hard to see however that the code is far from optimal and later when, for example, we want to
send a copy to the submitter, add an attachment, format the body, our save() method will have bloated
beyond its purpose. With that in mind let??™s refactor out the mailing code from the save() method and
create a SupportMailer class which can focus on that task.


Pages:
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
wentylatory serwery kadencja10 architekci programy partnerskie