<?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>djsipe.com &#187; php</title>
	<atom:link href="http://blog.djsipe.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.djsipe.com</link>
	<description>Web Development</description>
	<lastBuildDate>Sat, 31 Dec 2011 16:25:34 +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>Using a Single Template with Zend Framework&#8217;s ViewRenderer</title>
		<link>http://blog.djsipe.com/2008/02/16/using-a-single-template-with-zend-frameworks-viewrenderer/</link>
		<comments>http://blog.djsipe.com/2008/02/16/using-a-single-template-with-zend-frameworks-viewrenderer/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 22:57:20 +0000</pubDate>
		<dc:creator>DJ</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.djsipe.com/2008/02/16/using-a-single-template-with-zend-frameworks-viewrenderer/</guid>
		<description><![CDATA[Update: With the release of Zend_Layout, the need to this sort of workaround has diminished. It&#8217;s no secret that I&#8217;m a big fan of the Zend Framework. After fumbling around with a primitive MVC application at work, I was instantly won over by the clean, and intuitive way they implement MVC. Round about version 0.9, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: </strong>With the release of <a href="http://framework.zend.com/manual/en/zend.layout.html" title="Zend_Layout" target="_blank">Zend_Layout</a>, the need to this sort of workaround has diminished.</p>
<p>It&#8217;s no secret that I&#8217;m a big fan of the <a href="http://framework.zend.com/" target="_blank">Zend Framework</a>.  After fumbling around with a primitive <a href="http://en.wikipedia.org/wiki/Model-view-controller" target="_blank">MVC</a> application at work, I was instantly won over by the clean, and intuitive way they implement MVC.  Round about version 0.9, the <a href="http://devzone.zend.com/article/2072-Zend-Frameworks-MVC-Introduces-the-ViewRenderer" target="_blank">ViewRenderer</a> was introduced.  ViewRenderer is, I&#8217;d say, 90% useful.  It makes certain assumptions about the way you&#8217;re using the framework.  If you color between the lines it&#8217;s a great help.</p>
<p>One thing I almost always have to do is override the way it selects and automatically renders templates based on controller and action names.  I typically roll with a single template and load elements into that template.  Of course, I could just disable ViewRenderer altogether, but it does do a lot of other things that I find helpful, like initializing the <a href="http://framework.zend.com/manual/en/zend.view.html" target="_blank">View</a>.</p>
<p>My solution: extend the default Zend_Controller_Action class.  There&#8217;s only a few things to do:</p>
<ol>
<li>Disable the auto-render functionality of ViewRenderer</li>
<li>Add a new <code>$_template</code> property to hold the template to render</li>
<li>Render a single template in the <code>postDispatch</code> method</li>
</ol>
<p>Here&#8217;s the code:</p>
<pre class="brush: php; title: ; notranslate">
require_once &quot;Zend/Controller/Action.php&quot;;

class Blink_Controller_Action extends Zend_Controller_Action
{
    protected $_template = &quot;defaultTemplate.phtml&quot;;

    public function init()
    {
        $this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender(true);
        parent::init();
    }

    public function postDispatch()
    {
        echo $this-&gt;view-&gt;render($this-&gt;_template);
    }
}
</pre>
<p>With our new controller action, we can then largely forget about rendering the View.  All we have to do is assign values to the View:</p>
<pre class="brush: php; title: ; notranslate">
require_once &quot;Blink/Controller/Action.php&quot;;

class MyController extends Blink_Controller_Action
{
    public function IndexAction ()
    {
        $this-&gt;view-&gt;myValue = &quot;some value&quot;;
        // Assign more values...
        // Do business logic...

        // Optionally, select a new template to render
        $this-&gt;_template = &quot;differentTemplate.phtml&quot;;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.djsipe.com/2008/02/16/using-a-single-template-with-zend-frameworks-viewrenderer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Boosting Front-End Load Time with PHP</title>
		<link>http://blog.djsipe.com/2008/01/20/boosting-front-end-load-time-with-php/</link>
		<comments>http://blog.djsipe.com/2008/01/20/boosting-front-end-load-time-with-php/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 17:13:42 +0000</pubDate>
		<dc:creator>DJ</dc:creator>
				<category><![CDATA[Front End]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.djsipe.com/2008/01/20/boosting-front-end-load-time-with-php/</guid>
		<description><![CDATA[On of the best tools around for helping you speed up your page load times is Yahoo!&#8217;s YSlow Firefox extension. I&#8217;ve been using it for a while and found it has some interesting insights on page load performance. Its recommendations come from Yahoo!&#8217;s &#8220;Exceptional Performance Team&#8221; 14 recommendations for speeding up page load times. If [...]]]></description>
			<content:encoded><![CDATA[<p>On of the best tools around for helping you speed up your page load times is Yahoo!&#8217;s <a href="http://developer.yahoo.com/yslow/" title="YSlow explained on Yahoo!'s Developer Network" target="_blank">YSlow</a> Firefox extension.  I&#8217;ve been using it for a while and found it has some interesting insights on page load performance.  Its recommendations come from Yahoo!&#8217;s &#8220;Exceptional Performance Team&#8221; 14 recommendations for speeding up page load times.  If you&#8217;d rather hear it right from <a href="http://video.yahoo.com/video/play?vid=1040890" target="_blank">the horses mouth</a>, have at, otherwise you can watch the conveniently embedded video below.</p>
<p><embed src="http://us.i1.yimg.com/cosmos.bcst.yahoo.com/player/media/swf/FLVVideoSolo.swf" style="margin: 0pt 10px 10px 0pt; float: left" flashvars="id=3880720&amp;emailUrl=http%3A%2F%2Fvideo.yahoo.com%2Futil%2Fmail%3Fei%3DUTF-8%26vid%3D1040890&amp;imUrl=http%253A%252F%252Fvideo.yahoo.com%252Fvideo%252Fplay%253Fei%253DUTF-8%2526vid%253D1040890&amp;imTitle=Steve%2BSouders%253A%2B%2526quot%253BHigh%2BPerformance%2BWeb%2BSites%253A%2B14%2BRules%2Bfor%2BFaster%2BPages%2526quot%253B&amp;searchUrl=http://video.yahoo.com/search/video?p=&amp;profileUrl=http://video.yahoo.com/video/profile?yid=&amp;creatorValue=ZXJpY21pcmFnbGlh&amp;vid=1040890" type="application/x-shockwave-flash" height="350" width="425"></embed>Briefly, the 14 recommendations are:</p>
<ol>
<li>Make fewer HTTP requests</li>
<li>Use a <a href="http://en.wikipedia.org/wiki/Content_Delivery_Network" target="_blank">CDN</a> (like Akamai)</li>
<li>Add an &#8220;Expires&#8221; header</li>
<li>Use GZIP compression</li>
<li>Put CSS at the top</li>
<li>Put JavaScript (JS) at the bottom</li>
<li>Avoid CSS expressions</li>
<li>Make JS and CSS external</li>
<li>Reduce DNS lookups</li>
<li>Minify JS</li>
<li>Avoid redirects</li>
<li>Remove duplicate scripts</li>
<li>Configure ETags</li>
<li>Make AJAX cacheable</li>
</ol>
<p>Since the video can probably explain each of these points better than I can, I&#8217;ll let them speak for themselves for the most part.  Lately though, I have been thinking a lot about two of them, namely #1 and #10: Make fewer HTTP requests and Minify JavaScript.  Bit by bit, I&#8217;ve been trying to get all our JavaScript files at work &#8220;minified&#8221; but, it&#8217;s an uphill battle with so many files being edited semi-frequently by people other than myself.  Since minified JavaScript is almost impossible to read without getting a headache, you&#8217;d have to keep the un-minified versions on tap somewhere and leave step by step instructions on how to minify them and then get them on the site.  Having people then copy and paste the minified versions into a single aggregate file is simply asking for trouble.</p>
<p>Then I found a key part of the solution: a port of <a href="http://javascript.crockford.com/jsmin.html" target="_blank">Crockford&#8217;s JSMin</a> to PHP.  This <a href="http://code.google.com/p/jsmin-php/" target="_blank">PHP version</a>, allows you to do something very powerful that the original JavaScript version did not.  Now you can use aggregate and minify all your JavaScript into a single HTTP request by calling a PHP script in your script tag which gathers and minifies all the JavaScript for the page.</p>
<p>So, say you wanted to aggregate and minify the JavaScript for your menu and rich text editor of choice.  In your HTML, you might use a script tag like this:</p>
<pre class="html-codeface">&lt;script type="text/javascript" src="/jsaggmin.php?features=menu/richtexteditor"&gt;&lt;/script&gt;</pre>
<p>On the server, <code>jsaggmin.php</code> would do look something like this:</p>
<pre class="php-codeface">
require "jsmin.php";

foreach (explode("/", $_GET['features']) as $feature)
{

    switch ($feature)
    {
        case "menu":
            echo JSMin::minify(file_get_contents("menu.js"));
            break;

        case "richtexteditor":
            echo JSMin::minify(file_get_contents("rte.js"));
            break;
    }

}</pre>
<p>Granted, this isn&#8217;t the complete solution, but it&#8217;s a leap in the right direction.  What is needed next (in addition to a caching mechanism) is a way to run the equivalent of <a href="http://www.jslint.com/" target="_blank">JSLint</a> on the server before the files are minified.  As a rule of thumb, if a JavaScript file can&#8217;t pass JSLint, it will blow up when minified.  So the PHP script would need to verify the JavaScript, and echo it as is if it fails to validate.  Otherwise, you&#8217;ve just minified and aggregated all the scripts on your page and can focus on the other 12 recommendations.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.djsipe.com/2008/01/20/boosting-front-end-load-time-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

