<?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>Midstride Solutions &#187; php</title>
	<atom:link href="http://blog.midstride.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.midstride.com</link>
	<description>Powerful, simple &#38; easy to use.</description>
	<lastBuildDate>Sat, 18 Apr 2009 20:21:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Top 10 links for December Week 1 &#8211; 2008</title>
		<link>http://blog.midstride.com/2008/12/08/top-10-links-for-december-week-1-2008/</link>
		<comments>http://blog.midstride.com/2008/12/08/top-10-links-for-december-week-1-2008/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 05:41:28 +0000</pubDate>
		<dc:creator>andre</dc:creator>
				<category><![CDATA[Web Strategy]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[it]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[top]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.midstride.com/?p=37</guid>
		<description><![CDATA[Here is the first installment of our top 10 links for the week &#8211; a selection of ten links we see as being very useful and important to the web development/business crowd.  This list covers both technical articles for developers and higher level business ones.


10 Useful RSS-Tricks and Hacks for Wordpress &#8211; Smashingmagazine
Great tips for [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the first installment of our top 10 links for the week &#8211; a selection of ten links we see as being very useful and important to the web development/business crowd.  This list covers both technical articles for developers and higher level business ones.<strong><br />
</strong></p>
<ol>
<li><a href="http://www.smashingmagazine.com/2008/12/02/10-useful-rss-hacks-for-wordpress/" target="_blank">10 Useful RSS-Tricks and Hacks for Wordpress &#8211; Smashingmagazine</a><strong><br />
</strong>Great tips for any user of wordpress that relies on RSS for syndicating content.  Most of these tips show you how to gain more control over your RSS feeds.</li>
<li><a href="http://www.ibm.com/developerworks/opensource/library/os-php-5goodhabits/index.html?ca=dgr-jw64os-php-5goodhabits&amp;S_TACT=105AGY46&amp;S_CMP=GRsitejw64" target="_blank">5 good programming habits in PHP</a><br />
General rules of thumbs for php programmers.   Some of the rules may make you think twice, like the rule of &#8220;Never copy and paste&#8221;.</li>
<li><a href="http://www.dailyblogtips.com/what-is-more-important-to-succeed-online-business-or-technical-skills/" target="_blank">What is More Important To Succeed Online:  Business or Technical Skills?</a><br />
A question for the ages, at least in the IT field, is it more important to be business or technical minded?  A very interesting article on how these skills have attributed to the success of several companies.</li>
<li><a href="http://news.cnet.com/8301-17939_109-10114050-2.html?part=rss&amp;tag=feed&amp;subj=Webware" target="_blank">Firefox 3.1 beta news &#8211; web workers</a><br />
A CNET article on Firefox 3.1.  The interesting part is how &#8220;web workers&#8221; can process work in the background.  Background processing would push the RIA movement further and I&#8217;m sure would lead to some very novel ideas from early adopters.</li>
<li><a href="http://nettuts.com/articles/news/how-to-setup-a-dedicated-web-server-for-free/" target="_blank">How to Setup a Dedicated Web Server for free &#8211; with Ubuntu</a><br />
A practical and useful article on how to setup a web server.  This is a very well written article that shows how far Linux has come in terms of ease of use.</li>
<li><a href="http://blog.guykawasaki.com/2008/12/how-to-use-twit.html" target="_blank">How to use Twitter as a tool</a><br />
An article by Guy Kawasaki on how to use Twitter for productivity.  It&#8217;s a very detailed post and for those new to Twitter, it explains the utility factor of Twitter beyond just being a gossip tool.</li>
<li><a href="http://www.smashingmagazine.com/2008/12/03/online-advertising-and-its-impact-on-web-design/" target="_blank">Online Advertising and Its Impact on Web Design</a><br />
An excellent article from Smashing Magazine on how online advertising affects web design.  It&#8217;s an interesting topic as web advertising is a primary means of revenue for the majority of blogs.</li>
<li><a href="http://nettuts.com/articles/web-roundups/top-10-biggest-web-dev-blunders-of-2008/" target="_blank">Top 10 Web Dev Blunders of 2008</a><br />
A list of some of the biggest &#8220;mistakes&#8221; we&#8217;ve seen on the web this year.</li>
<li><a href="http://www.techcrunch.com/2008/12/02/who-protects-the-internet/" target="_blank">Who Protects The Internet?</a><br />
Who does protect the Internet?  This article should be of interest to anyone who uses the Internet, so that&#8217;s a lot of people.  Techcrunch takes a go at reviewing where we are with the Internet.</li>
<li><a href="http://www.dailyblogtips.com/referrer-detector-wordpress-plugin/" target="_blank">Referrer Detector Wordpress Plugin</a><br />
A great wordpress tool to greet your users coming from specific sites.</li>
</ol>
<p>I hope you find these articles useful.  You can contribute your own links by visiting this <a href="http://www.buncholinks.com/p/andreliem/decweek1top">buncholink</a> which groups related links together in a useful manner.</p>
<p><script src="http://www.buncholinks.com/widget/script/i/164/k/d864d5977385c962710cad06a4913732" type="text/javascript"></script></p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=Midstride%20Solutions&amp;siteurl=http%3A%2F%2Fblog.midstride.com%2F&amp;linkname=Top%2010%20links%20for%20December%20Week%201%20%E2%80%93%202008&amp;linkurl=http%3A%2F%2Fblog.midstride.com%2F2008%2F12%2F08%2Ftop-10-links-for-december-week-1-2008%2F"><img src="http://blog.midstride.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Top 10 links for December Week 1 – 2008";
		a2a_linkurl="http://blog.midstride.com/2008/12/08/top-10-links-for-december-week-1-2008/";
						    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.midstride.com/2008/12/08/top-10-links-for-december-week-1-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 tips and tools to optimize your php application &#8211; Part 1 simple</title>
		<link>http://blog.midstride.com/2008/12/01/5-tips-and-tools-to-optimize-your-php-application-part-1-simple/</link>
		<comments>http://blog.midstride.com/2008/12/01/5-tips-and-tools-to-optimize-your-php-application-part-1-simple/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 06:41:26 +0000</pubDate>
		<dc:creator>andre</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[minify]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[yslow]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://blog.midstride.com/?p=33</guid>
		<description><![CDATA[With php becoming a more mature language and frameworks becoming a standard practice, it&#8217;s increasingly important to analyze your code and test the performance where possible.
Frameworks and libraries can speed up the development time and make code maintenance simpler, but it&#8217;s important you understand how they work.  It&#8217;s not just the framework itself but the [...]]]></description>
			<content:encoded><![CDATA[<p>With php becoming a more mature language and frameworks becoming a standard practice, it&#8217;s increasingly important to analyze your code and test the performance where possible.</p>
<p>Frameworks and libraries can speed up the development time and make code maintenance simpler, but it&#8217;s important you understand how they work.  It&#8217;s not just the framework itself but the entire footprint your application leaves when a user visits a specific page.  Ask yourself what&#8217;s involved from the database, to the code/framework, and then to the client through http requests.<br />
<span id="more-33"></span><br />
After experiencing some issues with an application running the Zend Framework, I realized there were a lot of things I was not doing to optimize my application.  There are simple and more complex actions you can take to speed up your application.  Since time is precious, and developers with an expertise on optimization are not always available, I&#8217;ve split this post into two sections (simple and more advanced).  This post focuses on the simple part.</p>
<p><strong>Simple tips and tools<br />
</strong></p>
<ol>
<li><strong>Use Firebug with YSlow<br />
</strong>Firebug and YSlow are powerful tools to analyze the front end of your site.  Run the most common request on your site and see what YSlow says.  Expect a low grade, probably a D or lower.  If you can reach a level C or greater you&#8217;re doing really well as some of the requirements are not practical for most applications.</p>
<blockquote><p>How-to:<br />
<strong>Net</strong>: How many calls are there?  Try to minize these calls and definitely remove any 404 calls as they can eat up server resources.</p>
<p><strong>Console</strong>:  Do you have a lot of POST calls?  Some libraries, like dojo&#8217;s javascript framework, can make a lot of POST requests.  Reduce these if possible.</p>
<p><strong>YSlow</strong>: Rules I would pay attention to:<br />
1. Make fewer HTTP Requests<br />
3. Add an Expires Header<br />
4. Gzip components (server related)<br />
5. Put CSS at the top<br />
6. Put JS at the bottom (not always possible)<br />
7. Avoid CSS expressions<br />
10. Minify JS</p></blockquote>
<p>Resources:<br />
<a href="http://getfirebug.com/">http://getfirebug.com/</a><br />
<a href="http://developer.yahoo.com/yslow/">http://developer.yahoo.com/yslow/</a><br />
<a href="http://developer.yahoo.com/performance/rules.html ">http://developer.yahoo.com/performance/rules.html </a></li>
<li><strong>Minify Javascript and CSS<br />
</strong>Minification is the process of compacting your scripts by removing extraneous content such as white space.   In addition, minification can make attempts at refactoring the code to remove redunancies.  If you want to play it safe, only remove white space to ensure your code is still running. The Yahoo compressor is one of the best minifiers out there and reduces both Javascript and CSS by a significant percentage.</p>
<blockquote><p>How-to:<br />
<strong>java -jar yuicompressor-x.y.z.jar -o style_minified.css style.css</strong></p>
<p>add the &#8220;&#8211;nomunge&#8221; to only do whitespace compressions.</p></blockquote>
<p>Resources:<br />
<a href="http://developer.yahoo.com/yui/compressor/">http://developer.yahoo.com/yui/compressor/</a><br />
<a href="http://dojotoolkit.org/docs/shrinksafe">http://dojotoolkit.org/docs/shrinksafe</a><br />
<a href="http://dean.edwards.name/packer/ ">http://dean.edwards.name/packer/ </a></li>
<li><strong>Merge css and js http requests</strong>- manually or automated<br />
Reduce the amount of calls you make to various CSS and JS files by merging them to one URL.  This is more work but will reduce the overhead.</p>
<blockquote><p>How-to &#8211; manually:<br />
This is really easy, take your css and copy and paste them together into one file.  Make sure your preserve the order of your css.  The same applies to your Javascript files.</p>
<p>How-to &#8211; Automated &#8211; google or your own custom:<br />
Google has a php script which can take various sources and return them as one.</p></blockquote>
<p>Resources:<br />
<a href="http://code.google.com/p/minify/">http://code.google.com/p/minify/</a><br />
<a href="http://reinholdweber.com/?p=37">http://reinholdweber.com/?p=37</a></li>
<li><strong>CSS Background Images are bad &#8211; usually</strong><br />
Using a div for all of your images with a background image is not that great for performance as it requires more calls.  I&#8217;ll be the first to admit it&#8217;s my favourite way to design, but you should try to avoid them where possible.  In addition, for hover states try using one large image with background-position calls to show specific parts.</p>
<blockquote><p>How to:<br />
Use <em><strong><code><span style="color: #000000;">background-position </span></code></strong></em>to select which portion of the large image you want to show.  There isn&#8217;t much more to explain.</p></blockquote>
</li>
<li><strong>GZip<br />
</strong>Gzipping files on the server side will reduce the amount of overhead significantly.  It adds a bit more on the server side, but generally the pay off should be well worth it.</p>
<blockquote><p>How to:<br />
It depends on your server situation, but here&#8217;s a snippet:<br />
mod_gzip_on Yes<br />
mod_gzip_item_include mime ^application/x-javascript$</p>
<p>Refer to <a href="http://snipplr.com/view/9017/gzip-your-components/">http://snipplr.com/view/9017/gzip-your-components/</a> for details</p></blockquote>
<p>Resources:<br />
<a href="http://developer.yahoo.com/performance/rules.html#gzip" target="_blank">http://developer.yahoo.com/performance/rules.html#gzip</a><br />
<a href="http://snipplr.com/view/9017/gzip-your-components/">http://snipplr.com/view/9017/gzip-your-components/</a></li>
</ol>
<p><strong>Conclusion<br />
</strong>That wraps up the simple part of this tutorial&#8230; really, that&#8217;s it!  The focus of these posts is to keep them simple and easy to use.  You may be surprised at how much faster your application runs when you apply these techniques.  I hope you found these useful or at least agree that these are good practices to apply.  In the next part I will examine more advanced methods of optimizing your application.</p>
<p><strong>Feedback<br />
</strong>Your feedback is always appreciated.  In addition to commenting, if you have more resources, please add them to my growing list of links through this buncholink</p>
<p><script src="http://www.buncholinks.com/widget/script/i/162/k/8b5f477e74ec6ed2ad68064aec4034c0" type="text/javascript"></script></p>
<p>It&#8217;s a simple way to organize a group of links together.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=Midstride%20Solutions&amp;siteurl=http%3A%2F%2Fblog.midstride.com%2F&amp;linkname=5%20tips%20and%20tools%20to%20optimize%20your%20php%20application%20%E2%80%93%20Part%201%20simple&amp;linkurl=http%3A%2F%2Fblog.midstride.com%2F2008%2F12%2F01%2F5-tips-and-tools-to-optimize-your-php-application-part-1-simple%2F"><img src="http://blog.midstride.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="5 tips and tools to optimize your php application – Part 1 simple";
		a2a_linkurl="http://blog.midstride.com/2008/12/01/5-tips-and-tools-to-optimize-your-php-application-part-1-simple/";
						    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.midstride.com/2008/12/01/5-tips-and-tools-to-optimize-your-php-application-part-1-simple/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>5 tips and tools to develop php applications fast</title>
		<link>http://blog.midstride.com/2008/09/09/5-tips-to-develop-php-applications-fast/</link>
		<comments>http://blog.midstride.com/2008/09/09/5-tips-to-develop-php-applications-fast/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 05:00:15 +0000</pubDate>
		<dc:creator>andre</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php frameworks]]></category>
		<category><![CDATA[rapid application development]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://blog.midstride.com/?p=19</guid>
		<description><![CDATA[In this post, I will discuss 5 tips and tools that the php community has provided to speed up development time and improve code quality.  These should help you out if you don't already know them, but if you do I would like to hear what you use to speed up your development time.]]></description>
			<content:encoded><![CDATA[<p>When web applications like <a href="http://www.basecamphq.com/" target="_blank">basecamp</a> started appearing, a lot of attention started turning to <a href="http://www.rubyonrails.org/" target="_blank">Ruby on Rails</a>.  Suddenly small groups of technically driven people could release powerful applications in a month or two.  With this awareness, the usability standards for web applications increased and so did the technical challenges for web developers and designers.  This movement sort of left php developers in the dust for a while.  While CakePHP and other frameworks came to the rescue, it didn&#8217;t seem like the php community wanted to match Ruby on Rails.  If anything, php has been looking to retain its strong foundations of being built upon a powerful, easy to use library and integrating new &#8220;web 2.0&#8243; like ideas to do more than Ruby on Rails.</p>
<p>In this post, I will discuss 5 tips and tools that the php community has provided to speed up development time and improve code quality.  These should help you out if you don&#8217;t already know them, but if you do I would like to hear what you use to speed up your development time.</p>
<p><span id="more-19"></span></p>
<ol>
<li><strong>Framework with the Model View Controller (MVC):<br />
</strong>This is old news, the MVC pattern is an industry accepted pattern to improve the organization and overall quality of your code.  Put your database code in the model layer, visual UI code in the view, and business application logic in the controller.  If you don&#8217;t know the MVC layer, you really should.</p>
<blockquote><p>My choice: <a href="http://framework.zend.com/manual/en/zend.controller.html" target="_blank">Zend Framework</a><br />
Why?  Easy to pick and choose what you want to use; strong momentum behind it; good documentation.</p></blockquote>
<p>Resources:<br />
<a href="http://framework.zend.com/manual/en/zend.controller.html" target="_blank">http://framework.zend.com/manual/en/zend.controller.html</a><br />
<a href="http://www.cakephp.org/" target="_blank">http://www.cakephp.org</a><br />
<a href="http://www.symfony-project.org/" target="_blank">http://www.symfony-project.org</a><br />
<a href="http://codeigniter.com/" target="_blank">http://codeigniter.com/</a></li>
<li><strong>AJAX Frameworks:</strong><br />
Also old news, you should become familiar with a common AJAX framework.  Scriptaculous, mootools, jquery, and dojo to name a few&#8230; these frameworks can all do similar things and will make your clients go ooh and ahh.  Actually, these days AJAX interaction is become standard.  Being a Zend developer, I would suggest acquainting yourself with the Dojo framework.  It&#8217;s probably the largest and most complex of them all but is very powerful.</p>
<blockquote><p>My choice: <a href="http://dojotoolkit.org/ " target="_blank">Dojo<br />
</a>Why?  Zend has adopted it into the zend framework; easy to extend; large resource of reusable widgets to use.</p></blockquote>
<p>Resources:<br />
<a href="http://en.wikipedia.org/wiki/Ajax_framework" target="_blank">http://en.wikipedia.org/wiki/Ajax_framework</a><br />
<a href="http://www.phpframeworks.com/" target="_blank">http://www.phpframeworks.com/</a><br />
<a href="http://mootools.net/" target="_blank">http://mootools.net/</a><br />
<a href="http://jquery.com/" target="_blank">http://jquery.com/</a><br />
<a href="http://script.aculo.us/" target="_blank">http://script.aculo.us/</a><br />
<a href="http://www.prototypejs.org/">http://www.prototypejs.org/</a><br />
<a href="http://dojotoolkit.org/ " target="_blank">http://dojotoolkit.org/ </a></li>
<li><strong>Integrated Development Environment (IDE):<br />
</strong> I won&#8217;t go into much detail here, if you&#8217;re developing objected oriented code or using a lot of libraries you should get a good IDE.  Eclipse PDT is my favourite because it&#8217;s free and has some very useful plugins to extend it.  My basic requiremnts are resource/file management of libraries, auto completion, basic syntax validation, and basic debugging tools.</p>
<blockquote><p>My choice:  <a href="http://www.eclipse.org/pdt/" target="_blank">Eclipse PDT</a><br />
Why?  It&#8217;s free and provides all the basic features an IDE should have.</p></blockquote>
<p>Resources:<br />
<a href="http://www.eclipse.org/pdt/" target="_blank">http://www.eclipse.org/pdt/</a><br />
<a href="http://www.zend.com/en/products/studio/" target="_blank">http://www.zend.com/en/products/studio/</a><br />
<a href="http://www.ibm.com/developerworks/opensource/library/os-php-ide/index.html" target="_blank">http://www.ibm.com/developerworks/opensource/library/os-php-ide/index.html</a></li>
<li><strong>Database Creation/Management Software</strong>:<br />
Managing a database schema can become tedious error prone thing to do.  If you don&#8217;t have a dedicated database team, and in many cases are the web and database developer, then you should be doing more than handling your schema in mysql (or your database of choice).  MySql has recently released workbench, a database management software that is really powerful.  I prefer DBDesigner 4 right now because it&#8217;s simple to use and feeds into <a href="http://propel.tigris.org/" target="_blank">propel db</a> well.  But I plan on moving over to workbench in the near future as it&#8217;s really the continuation of DBDesigner.</p>
<blockquote><p>My choice: <a href="http://fabforce.net/dbdesigner4/ " target="_blank"> DBDesigner</a>, but not for long.<br />
Why?  It&#8217;s simple to manage your database schema visually and exports well.</p></blockquote>
<p>Resources:<br />
<a href="http://dev.mysql.com/workbench/" target="_blank">http://dev.mysql.com/workbench/</a><br />
<a href="http://fabforce.net/dbdesigner4/ " target="_blank">http://fabforce.net/dbdesigner4/ </a></li>
<li><strong>Object Relational Mapping (ORM)</strong>:<br />
If you don&#8217;t know what this is, it&#8217;s basically a way of mapping your database tables to objects.  It&#8217;s so you don&#8217;t have to think about how to connect your logic/business code to the database.  Also, if you use tools like Propel DB you don&#8217;t have to code this as it generates it all for you.  While your application may not perform as well as with straight SQL, you will code faster and you can find ways to tweak bottle neck cases.</p>
<blockquote><p>My choice:  <a href="http://propel.tigris.org/" target="_blank">Propel DB<br />
</a>Why?  It&#8217;s easy to use and integrate into the zend framework; There aren&#8217;t many other options.</p></blockquote>
<p>Resources:<br />
<a href="http://en.wikipedia.org/wiki/Object-relational_mapping" target="_blank">http://en.wikipedia.org/wiki/Object-relational_mapping</a><br />
<a href="http://propel.tigris.org/" target="_blank">http://propel.tigris.org/ </a></li>
</ol>
<h2>Wrap Up / Further thoughts</h2>
<p>I hope this was useful for you.  Everyone has their own combination that works for them, and in a lot of cases the company forces you to use one.  Where I work, we can use whatever combination we want and I know there are many.  I would like to hear what your setup is like, what IDE, framework, and OS works for you and why?</p>
<p>Comment/Get the links for this post here:<br />
<script src="http://www.buncholinks.com/widget/script/i/59/k/305ff773469a6fcd760e059d2c266b2c" type="text/javascript"></script></p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=Midstride%20Solutions&amp;siteurl=http%3A%2F%2Fblog.midstride.com%2F&amp;linkname=5%20tips%20and%20tools%20to%20develop%20php%20applications%20fast&amp;linkurl=http%3A%2F%2Fblog.midstride.com%2F2008%2F09%2F09%2F5-tips-to-develop-php-applications-fast%2F"><img src="http://blog.midstride.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="5 tips and tools to develop php applications fast";
		a2a_linkurl="http://blog.midstride.com/2008/09/09/5-tips-to-develop-php-applications-fast/";
						    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.midstride.com/2008/09/09/5-tips-to-develop-php-applications-fast/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Integrating AJAX/Dojo into the Zend MVC in 8 steps.</title>
		<link>http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/</link>
		<comments>http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 04:39:23 +0000</pubDate>
		<dc:creator>andre</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://blog.midstride.com/?p=7</guid>
		<description><![CDATA[If you have been following the Zend Framework at all, you'll know that Dojo has been selected as the UI library to be adopted into the Zend Framework. The question is what does this exactly mean? ]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p><a href="http://blog.midstride.com/wp-content/uploads/2008/09/zend_dojo.jpg"><img class="alignnone size-thumbnail wp-image-14 alignleft" style="float: left;" title="zend_dojo" src="http://blog.midstride.com/wp-content/uploads/2008/09/zend_dojo-150x118.jpg" alt="" width="150" height="118" /></a>If you have been following the <a href="http://framework.zend.com/" target="_blank">Zend Framework</a> at all, you&#8217;ll know that <a href="http://dojotoolkit.org/">Dojo </a>has been selected as the UI library to be adopted into the Zend Framework.  The question is what does this exactly mean?  I&#8217;m still trying to figure out how they are going to use dojo, but right now with release 1.6 you can create dojo widgets (e.g. &#8211; date pickers, currency boxes, specialized buttons etc&#8230;) in code with the Zend_Dojo object.   That being said, you still need to learn a few more things to create a useful and reusable AjAX framework with Zend.<br />
<span id="more-7"></span></p>
<h3>The Goal</h3>
<p>This tutorial will explain how to create a reusable UI AJAX layer with dojo that communicates to the Zend controller class.  I&#8217;ll provide some basic code that will show you one way of creating a reusable framework that makes it easier to organize your javascript/ajax and controller layer.</p>
<h3>Prerequisites</h3>
<p>Before you proceed, you&#8217;ll need to read up on how to setup the Zend MVC framework.</p>
<ul>
<li><a href="http://framework.zend.com/manual/en/zend.controller.html">Zend Framework with a MVC structure</a></li>
<li><a href="http://dojotoolkit.org/downloads">Dojo framework</a></li>
</ul>
<h3>The Steps</h3>
<p>1. Setup the Zend Framework and a MVC structure</p>
<p>2. Create the controller class file (e.g. &#8211; MidstrideController.php)</p>
<p>3. Create the view folder &#8220;midstride&#8221; in the view/scripts directory.</p>
<p>4. Create the file &#8220;index.phtml&#8221; in the midstride views/scripts folder.</p>
<p>5. Create an empty javascript file called ajaxmethods.js and place it in your javascript folder.</p>
<p><em><strong>-check up-<br />
</strong></em>Your file structure should look something like this now:</p>
<p>-/application/controller/MidstrideController.php<br />
-/application/views/scripts/midstride/index.phtml<br />
-/www/javascript/ajaxmethods.js<br />
-/www/scriptslib/dojo-release-1.1.1</p>
<p>Where application is your MVC folder and www is the directory for your assets and index.php bootstrap file.</p>
<p>5. Add the javascript code to the header of index.phtml</p>
<pre class="programlisting"> <code>
<span style="color: #000000;">
&lt;script type="text/javascript" src="&lt;?php echo $this-&gt;baseUrl; ?&gt;/javascript/ajaxmethods.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript" src="&lt;?php echo $this-&gt;baseUrl;?&gt;/scriptslib/dojo-release-1.1.1/dojo/dojo.js"         djConfig="parseOnLoad: true"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;

dojo.require("dojo.parser");

&lt;/script&gt;

</span>
</code></pre>
<p>In this case, the baseUrl is a short cut variable defined in your controller class<br />
e.g. &#8211; $this-&gt;view-&gt;baseUrl = $this-&gt;_request-&gt;getBaseUrl();   //gets the root of your application</p>
<p>6. Add some sample form information to index.phml</p>
<pre class="programlisting"> <code>
<span style="color: #000000;">
&lt;div id="status_message"&gt;&lt;!-- ajax messages go here--&gt;&lt;/div&gt;

&lt;form id="ajax_form"&gt;

&lt;input type="text" name="test_input" value="12345" /&gt;

&lt;input id="submit_button" type="submit"

value="submit"

onclick="formPost('&lt;?php echo $this-&gt;baseUrl ?&gt;/midstride/ajaxcall',"ajax_form","ajax_loader","submit_button") /&gt;

&lt;div id="ajax_loader" class="ajax_loader" style="display:none;"  /&gt;

&lt;/form&gt;

</span>
</code></pre>
<p>This form will call the javascript function &#8220;formPost&#8221; with the id of the ajax loader which is currently hidden.  The next step is to define the javascript function which will do the ajax call.</p>
<p>7. Code a reusable javascript ajax function</p>
<pre class="programlisting"> <code>
<span style="color: #000000;">
function formPost(destinationUrl, formId, loaderId, submitId)

{

var useAjaxLoader= true;

var hideSubmitAction = true;

if (loaderId===undefined) {     useAjaxLoader = false; }

if (submitId===undefined) {     hideSubmitAction  = false; }

var postParams = { url: destinationUrl,

load: function(data) {

dojo.eval(data);

//hide ajax loader

if (useAjaxLoader)    { dojo.byId(loaderId).style.display = "none";}

if (hideSubmitAction) { dojo.byId(submitId).style.display = "";} },

error: function(data) { console.debug("An error occurred: ", data); },

form: formId,

timeout: 4000,

headers: { "X-Requested-With": "XMLHttpRequest" }

};

//show ajax loader

if (hideSubmitAction) {dojo.byId(submitId).style.display = "none";}

if (useAjaxLoader)    {dojo.byId(loaderId).style.display = "";} //block

dojo.xhrPost(postParams);

}

</span>
</code></pre>
<p>There&#8217;s a lot going on in this code but it&#8217;s not that complex.  In short:</p>
<ul>
<li>destinationUrl = the HTTP address you want to call (a controller action method).</li>
<li>formId = the id of the form that is making the call.</li>
<li>loaderId = the id of the ajax loader (optional)</li>
<li>submitId = the id of the submit button (optional)</li>
</ul>
<p>The loaderId and submitId are used to show a loading icon and hide the submit button.  This provides the nice ajax feedback and makes sure the user doesn&#8217;t click twice.</p>
<p>The destinationUrl is the same address as in the GET or POST URL.  We need to pass the formId so that the parameters can be passed.  I&#8217;ll explain at the end other ways of passing parameters.</p>
<p>8.  Create some sample php code in the controller class &#8220;MidstrideController.php&#8221;</p>
<pre class="programlisting"> <code>
<span style="color: #000000;">
[in MidstrideController.php]

public function ajaxcallAction()

//only handle ajax calls

if ($this-&gt;_request-&gt;isXmlHttpRequest())

{

//don't render the page - no view script is needed{

$this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender();

//json is the intermediate language to pass messages between the server and client

$jsonData = "";  //initialize to nothing
//get the parameter as normal

$testValue = $this-&gt;_request-&gt;getParam("test_value");

//prepare a fancy highlight response back

$jsonData =  "var highlight = dojo.animateProperty(

{

node: 'status_message',duration: 500,

properties: {

color:         { start: 'white', end: 'black' },

backgroundColor:{ start: '#fffecc', end: '#ffffff' }

}

});highlight.play();"

$this-&gt;_response-&gt;appendBody($jsonData);

}

}

</span>
</code></pre>
<p>This action method listens for the ajax called made by the javascript function.  It only deals with <strong>XmlHttpRequests (AJAX)</strong> and then sets the controller to not render anything.  The no rendering option means you don&#8217;t need to create a view (phtml) script.  Next, you just handle the form data as you would normally and prepare a JSON response to send back.  In this case, I&#8217;ve prepared a dojo animation to make a nice highlight on a status box.  In practice, you may not want to include any javascript in your controller class, as this is technically UI logic that could be in the ajax (JS) layer.  I prefer including dojo javascript because I don&#8217;t like writing javascript <img src='http://blog.midstride.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>The last call <strong>$this-&gt;_response-&gt;appendBody($jsonData)</strong> returns a javascript string which is evaluated in your javascript function by <strong>dojo.eval(data)</strong>.</p>
<h3>You&#8217;re done</h3>
<p>That&#8217;s it!  You now have a simple way of making ajax calls and keeping your main logic in the controller layer, where it should be.   If you wanted to  pass more parameters to the controller class, you would have to modify the formPost() function to have this:</p>
<blockquote><p>contentParams =  { &#8220;paramOne&#8221;:&#8221;1&#8243;,&#8221;paramTwo&#8221;:&#8221;2  };</p></blockquote>
<p>and then pass this to the var post params like:</p>
<blockquote><p>var postParams { content:contentParams, &#8230;other parameters}</p></blockquote>
<p>This can be useful when you have hidden values or other non traditional form inputs to pass in.</p>
<h3>Pros</h3>
<p>-8 steps to a reusable ajax layer.<br />
-You can easily customize the ajax post effects with dojo&#8217;s large animation library.<br />
-A very customizable and flexible framework for any project.</p>
<h3>Cons</h3>
<p>-Technical level:  It can take a while to learn the MVC and Dojo library.</p>
<h3>Conclusion</h3>
<p>That wraps up my first article on AJAX and the Zend Framework.  Future upcoming AJAX articles will discuss how to integrate Zend in scenarios where you want a real progress bar, modal popups, and captcha services.  Please let me know if you have any comments or questions.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=Midstride%20Solutions&amp;siteurl=http%3A%2F%2Fblog.midstride.com%2F&amp;linkname=Integrating%20AJAX%2FDojo%20into%20the%20Zend%20MVC%20in%208%20steps.&amp;linkurl=http%3A%2F%2Fblog.midstride.com%2F2008%2F08%2F26%2Fintegrating-ajaxdojo-into-the-zend-mvc-in-8-steps%2F"><img src="http://blog.midstride.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Integrating AJAX/Dojo into the Zend MVC in 8 steps.";
		a2a_linkurl="http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/";
						    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
