User Profile
- User
- mhuggins
- Location
- Pflugerville, TX
- Time Zone
- URL
- http://blackbooksingles.com
Recent Articles
Improved SwiftMailer Component
I've used the [url=http://bakery.cakephp.org/articles/view/sending-email-with-phpmailer]PHPMailer component[/url] previously, and it's useful for basic SMTP usage. However, I recently needed to make an SMTP connection requiring TLS authentication, which PHPMailer does not provide.
To resolve this, I decided to switch to SwiftMailer. Unfortunately, I wasn't very satisfied with the ease of use of the existing [url=http://bakery.cakephp.org/articles/view/swiftmailer-component]SwiftMailer component[/url] I found on the Bakery.
As such, I created my own component that is more similar to the original PHPMailer component I was using. It doesn't have attachments implemented, but it's handy for sending HTML/plaintext emails.
- Published by mhuggins 06/11/08 - 13:41
- 12090 views
- 9 comments







1. Internationalization Improvement
Utilize sprintf in conjunction with %s/%d/etc. placeholders in your string. This way you only have to convert one string in LC_MESSAGES instead of multiple similar strings.
For example, I changed this:
trigger_error(__('Process Callback not found. Please create Controller::' . $processCallback, true), E_USER_WARNING);...to this:
trigger_error(sprintf(__('Process Callback not found. Please create Controller::%s', true), $processCallback), E_USER_WARNING);Similarly, I changed this:
trigger_error(__('Step validation: ' . $step . ' is not a valid step.', true), E_USER_WARNING);...to this:
trigger_error(sprintf(__('Step validation: %s is not a valid step.', true), $step), E_USER_WARNING);2. View Rendering Improvement
Several of my prepare steps simply reuse existing views via Controller::render(). Typically, this prevents a view from autoRendering in CakePHP. I would recommend the WizardComponent do the same by not autoRendering if a view has already been rendered.
I did this by changing this line of the Component:
return $this->controller->render($this->_currentStep);...to this:
return $this->controller->autoRender ? $this->controller->render($this->_currentStep) : true;