<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TK Studios &#187; php</title>
	<atom:link href="http://www.tkstudios.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tkstudios.com</link>
	<description>Web Application Design &#38; Development</description>
	<lastBuildDate>Mon, 20 Jun 2011 16:07:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Disable WP&#8217;s Automatic Paragraphs</title>
		<link>http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/</link>
		<comments>http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 16:07:28 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=266</guid>
		<description><![CDATA[A quick hack to disable the wpautop() function&#8217;s tendency to mangle your WordPress-based HTML posts with extra markup: Add the following to your functions.php: function custom_autop($p, $br = 1) { if (stristr($p, '&#60;!--noautop--&#62;')) { return str_ireplace('&#60;!--noautop--&#62;', '', $p); } else {     return wpautop($p, $br);   } } remove_filter('the_content','wpautop'); add_filter('the_content','custom_autop'); That&#8217;s it. Now when [...]]]></description>
			<content:encoded><![CDATA[<p>A quick hack to disable the <strong>wpautop()</strong> function&#8217;s tendency to mangle your WordPress-based HTML posts with extra markup:</p>
<p>Add the following to your <strong>functions.php</strong>:</p>
<pre>function custom_autop($p, $br = 1) {
  if (stristr($p, '&lt;!--noautop--&gt;')) {
    return str_ireplace('&lt;!--noautop--&gt;', '', $p);
  } else {
    return wpautop($p, $br);
  }
}
remove_filter('the_content','wpautop');
add_filter('the_content','custom_autop');</pre>
<p>That&#8217;s it. Now when you add <strong>&lt;!&#8211;noautop&#8211;&gt; </strong>to a post, it&#8217;ll disable the wpautop() function.</p>
<p>Incidentally, wpautop has a parameter called &#8220;$pee&#8221; and a loop that reads &#8220;foreach( $pees as $tinkle )&#8221; &#8230;</p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Disable+WP%E2%80%99s+Automatic+Paragraphs+http%3A%2F%2Fis.gd%2FtHw2Me+%28%40tkstudios%29" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=Disable+WP%E2%80%99s+Automatic+Paragraphs+http%3A%2F%2Fis.gd%2FtHw2Me+%28%40tkstudios%29" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/&amp;title=Disable+WP%E2%80%99s+Automatic+Paragraphs" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/&amp;title=Disable+WP%E2%80%99s+Automatic+Paragraphs" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/&amp;title=Disable+WP%E2%80%99s+Automatic+Paragraphs" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/&amp;title=Disable+WP%E2%80%99s+Automatic+Paragraphs" title="Post to Reddit">Post to Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/&amp;title=Disable+WP%E2%80%99s+Automatic+Paragraphs" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/&amp;title=Disable+WP%E2%80%99s+Automatic+Paragraphs" title="Post to StumbleUpon">Stumble This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2011/06/20/disable-wps-automatic-paragraphs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpScenario, a split testing library</title>
		<link>http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/</link>
		<comments>http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 22:35:59 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[phpScenario]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[free stuff]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=173</guid>
		<description><![CDATA[I&#8217;m closing in on the first release of what you might call a by-product of Listy.us; phpScenario is a free split-testing library created out of the need to have a way of testing various ideas on Listy.us without relying on paid products or offsite solutions. I&#8217;m going to release it for free, though I haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m closing in on the first release of what you might call a by-product of Listy.us; <strong><a title="phpScenario: Free Split Testing Library for PHP" href="http://www.phpscenario.org/">phpScenario</a></strong><a title="phpScenario: Free Split Testing Library for PHP" href="http://www.phpscenario.org/"> is a free split-testing library</a> created out of the need to have a way of testing various ideas on Listy.us without relying on paid products or offsite solutions. I&#8217;m going to release it for <strong>free</strong>, though I haven&#8217;t chosen a license yet. (update: New BSD license!)</p>
<p><span id="more-173"></span></p>
<p>At the core, I wanted it to be as simple as possible to create new tests, but still have a good degree of flexibility. Basically by default, it assumes you want a A/B 50% split test using the php session ID as the identity. If you have a class defined as [Prefix_]TestName, it&#8217;ll load that as the experiment object instead of the default class, and you can do any additional cases (a/b/c/d?) and/or weighting in the treatment selection method. One treatment must always be named &#8220;default&#8221;.</p>
<p>The simplest possible usage case, after setting up your database, is essentially this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Scenario<span style="color: #339933;">::</span><span style="color: #004000;">IsControl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myExperiment'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// do something </span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// do something different</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next, in your conversion point, you&#8217;d do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Scenario<span style="color: #339933;">::</span><span style="color: #004000;">Complete</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myExperiment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Easy, right? Rendering results looks like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Scenario<span style="color: #339933;">::</span><span style="color: #004000;">RenderXml</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myExperiment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The html output looks like this (data set is basically a bunch of randomized 50/50 data):</p>
<p><a href="http://www.tkstudios.com/wp-content/uploads/2010/10/Screen-shot-2010-10-06-at-5.54.40-PM.png"><img class="alignnone size-full wp-image-174" title="Screen shot 2010-10-06 at 5.54.40 PM" src="http://www.tkstudios.com/wp-content/uploads/2010/10/Screen-shot-2010-10-06-at-5.54.40-PM.png" alt="" width="378" height="284" /></a></p>
<p>If you specify &#8220;xml&#8221; for the translation, you&#8217;ll get something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Scenario<span style="color: #339933;">::</span><span style="color: #004000;">RenderXml</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myExperiment'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="http://www.tkstudios.com/wp-content/uploads/2010/10/Screen-shot-2010-10-06-at-6.42.25-PM.png"><img class="alignnone size-full wp-image-177" title="Screen shot 2010-10-06 at 6.42.25 PM" src="http://www.tkstudios.com/wp-content/uploads/2010/10/Screen-shot-2010-10-06-at-6.42.25-PM.png" alt="" width="513" height="200" /></a></p>
<p>Lots of thanks to <a href="http://20bits.com/">Jesse Farmer</a> for his <a title="Statistical Analysis and A/B Testing at 20Bits.com" href="http://20bits.com/articles/statistical-analysis-and-ab-testing/">incredibly useful article on statistical analysis and A/B testing</a>. That article saved me a lot of headaches in attempting to decode the wikipedia article on the underlying concept. Seriously, wiki is freakin&#8217; horrible when it comes to plain english explanations of mathematical concepts.</p>
<p>Any suggestions or feature requests while I&#8217;m in the documentation / tweaking phase?</p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=phpScenario%2C+a+split+testing+library+http%3A%2F%2Fis.gd%2FllIF1k+%28%40tkstudios%29" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=phpScenario%2C+a+split+testing+library+http%3A%2F%2Fis.gd%2FllIF1k+%28%40tkstudios%29" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/&amp;title=phpScenario%2C+a+split+testing+library" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/&amp;title=phpScenario%2C+a+split+testing+library" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/&amp;title=phpScenario%2C+a+split+testing+library" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/&amp;title=phpScenario%2C+a+split+testing+library" title="Post to Reddit">Post to Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/&amp;title=phpScenario%2C+a+split+testing+library" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/&amp;title=phpScenario%2C+a+split+testing+library" title="Post to StumbleUpon">Stumble This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2010/10/06/phpscenario-a-split-testing-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP hashing performance experiment</title>
		<link>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/</link>
		<comments>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 05:26:52 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Listy]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=150</guid>
		<description><![CDATA[Today, in the never-ending quest to tweak server performance by a few milliseconds, I decided to do a bit of testing of various php hashing methods. I therefore wrote a quick script under php (5.2.11 currently, I need to update), which ran each test case 10,000 times to achieve a decent min/avg/max for each case, [...]]]></description>
			<content:encoded><![CDATA[<p>Today, in the never-ending quest to tweak server performance by a few milliseconds, I decided to do a bit of testing of various php hashing methods. I therefore wrote a quick script under php (5.2.11 currently, I need to update), which ran each test case 10,000 times to achieve a decent min/avg/max for each case, on strings of 10KB, 100KB, and 1,000KB in size.</p>
<p><span id="more-150"></span></p>
<p>The short version of the result is that the md5() function won across the board. The comments in the <a title="PHP: hash - Manual" href="http://us.php.net/manual/en/function.hash.php">php.net hash function documentation</a> seemed to indicate a performance increase in using hash(&#8216;md5&#8242;,$str), and an even better increase in hash(&#8216;md4&#8242;,$str). I found this to only partially be the case; While using the hash function, md4 is minutely faster than md5, the md5() function itself is considerably faster than either of these.</p>
<p>So, for any performance sensitive case, I would say md5() is by far the best choice.</p>
<p>Actual results of the test suite can be seen here:</p>
<p><a href="http://listy.us/list/view/153"><img src="http://www.listy.us/list/banner/153" alt="PHP Hash Performance by JSylvanus via Listy.us" /></a></p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=PHP+hashing+performance+experiment+http%3A%2F%2Fis.gd%2FHclqbV+%28%40tkstudios%29" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=PHP+hashing+performance+experiment+http%3A%2F%2Fis.gd%2FHclqbV+%28%40tkstudios%29" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Reddit">Post to Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to StumbleUpon">Stumble This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework: Email templating with layouts &amp; views</title>
		<link>http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/</link>
		<comments>http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 16:14:24 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Listy]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=99</guid>
		<description><![CDATA[This is a solution that I came up with for sending out welcome emails, comment notifications, etc, with nice standardized HTML &#38; text layouts, using a few components of the Zend Framework. Basically you create a view (here called $renderer) and a layout ($layout), then render your views and layouts for both HTML and text [...]]]></description>
			<content:encoded><![CDATA[<p>This is a solution that I came up with for sending out welcome emails, comment notifications, etc, with nice standardized HTML &amp; text layouts, using a few components of the Zend Framework.</p>
<p>Basically you create a view (here called $renderer) and a layout ($layout), then render your views and layouts for both HTML and text versions. My file tree looks like this:</p>
<pre>application/
	emails/
		welcome.html.phtml
		welcome.text.phtml
		layouts/
			layout.html.phtml
			layout.text.phtml</pre>
<p>So, &#8216;welcome&#8217; would be your template name, with html and text versions. The layout is what you want wrapped around either version of every email you send out (header graphics, font settings, contact info, etc).</p>
<p><span id="more-99"></span></p>
<p>I keep all of my mail functions in one class, creating a new function for each email that needs to be sent out regularly in an automatic fashion. You could even use this for newsletters, but I prefer more robust environments like <a href="http://www.mailchimp.com/">MailChimp</a> or <a href="http://www.campaignmonitor.com/">CampaignMonitor</a> for that sort of thing.</p>
<p>This simple function handles all the rendering, file paths, etc. It just needs to be called with the proper template name, and an array of items to be passed to the view renderer.</p>
<p>Here&#8217;s the meat of it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * getMailContent
 * Renders mailer content in text and html and passes it back as an array('html'=&amp;gt;content,'text'=&amp;gt;content)
 *
 * @param string $templatename the name of the email template to use (APP/emails/[name].[format].phtml)
 * @param array $substitutions key=&amp;gt;value array of variables to pass to the view renderers
 * @return array
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getMailContent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$templatename</span><span style="color: #339933;">,</span> <span style="color: #000088;">$substitutions</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// create a view renderer and set it to app_path/emails/</span>
    <span style="color: #000088;">$renderer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_View<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$renderer</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setScriptPath<span style="color: #009900;">&#40;</span><span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span>APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/emails/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// create a layout object and set it to app_path/emails/layouts</span>
    <span style="color: #000088;">$layout</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Layout<span style="color: #009900;">&#40;</span>APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/emails/layouts/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$layout</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setView<span style="color: #009900;">&#40;</span><span style="color: #000088;">$renderer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this probably isn't even necessary</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// assign all substitutions (e.g. view variables) to the view renderer</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$substitutions</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$sub</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$renderer</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sub</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// output array        </span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// render text version of template &amp;amp; assign to output['text']</span>
    <span style="color: #000088;">$layout</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>content <span style="color: #339933;">=</span> <span style="color: #000088;">$renderer</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$templatename</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.text.phtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$layout</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setLayout<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'layout.text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$output</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$layout</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>render<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// render html version of template &amp;amp; assign to output['html']</span>
    <span style="color: #000088;">$layout</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>content <span style="color: #339933;">=</span> <span style="color: #000088;">$renderer</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$templatename</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.html.phtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$layout</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setLayout<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'layout.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$output</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'html'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$layout</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>render<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// all done, return output</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Nice and simple, huh? All you need to do is call it and then assign the output to your Zend_Mail object like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #000088;">$bodies</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getMailContent<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'new_comment'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'comment'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'comment_list'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$comment_list</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'comment_user'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$comment_user</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'list_owner'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$list_owner</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$mail</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setBodyHtml<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bodies</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'html'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$mail</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setBodyText<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bodies</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Your email template accesses the variables passed to it just as it would a normal view script:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #009900;">&#91;</span>variable<span style="color: #009900;">&#93;</span></pre></div></div>

<p>Commentary / suggestions / etc welcome in comments.</p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Zend+Framework%3A+Email+templating+with+layouts+%26+views+http%3A%2F%2Fis.gd%2FR6j2qY+%28%40tkstudios%29" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=Zend+Framework%3A+Email+templating+with+layouts+%26+views+http%3A%2F%2Fis.gd%2FR6j2qY+%28%40tkstudios%29" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to Reddit">Post to Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to StumbleUpon">Stumble This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

