<?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>Hawk Host Blog &#187; Programming</title>
	<atom:link href="http://blog.hawkhost.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hawkhost.com</link>
	<description>All things Hawk Host</description>
	<lastBuildDate>Tue, 02 Mar 2010 01:47:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AJAX Zend Framework Tips</title>
		<link>http://blog.hawkhost.com/2009/11/21/ajax-zend-framework-tips/</link>
		<comments>http://blog.hawkhost.com/2009/11/21/ajax-zend-framework-tips/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 21:24:55 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.hawkhost.com/?p=561</guid>
		<description><![CDATA[I&#8217;ve been doing some work with Zend Framework in the javascript front and I figured I may as well post a bunch of the things I&#8217;ve noticed as of recently that might be useful for others.
Adding javascript files on a specific controller

What you want your layout to look like:

&#60;?php echo $this-&#62;doctype(); ?&#62;
&#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34; xml:lang=&#34;en&#34; lang=&#34;en&#34;&#62;
&#60;head&#62;
 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing some work with Zend Framework in the javascript front and I figured I may as well post a bunch of the things I&#8217;ve noticed as of recently that might be useful for others.</p>
<p><strong>Adding javascript files on a specific controller</strong></p>
<p><span id="more-561"></span></p>
<p>What you want your layout to look like:</p>
<pre class="brush: php;">
&lt;?php echo $this-&gt;doctype(); ?&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
    	&lt;?php echo $this-&gt;HeadMeta(); ?&gt;
    	&lt;?php echo $this-&gt;headTitle(); ?&gt;
	&lt;?php echo $this-&gt;headScript() ?&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;content&quot;&gt;
    &lt;h1&gt;&lt;?php echo $this-&gt;escape($this-&gt;title); ?&gt;&lt;/h1&gt;
    &lt;?php echo $this-&gt;layout()-&gt;content; ?&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Here&#8217;s an example controller:</p>
<pre class="brush: php;">
class IndexController extends Zend_Controller_Action
{
	public function init()
    	{
        	$this-&gt;view-&gt;headScript()-&gt;appendFile('path/to/my/javascript/file');
    	}
    	/* Inside an action */
	public function indexAction()
	{
		$this-&gt;view-&gt;headScript()-&gt;appendFile('path/to/my/other/javascript/file');
	}
}
</pre>
<p>This portion will allow you to do things where you want a javascript file on a specific controller only.  Or even in some cases you want it on a specific action and it all can be handled with Zend Framework rather than customizations to your layout with special view flags you added yourself.</p>
<p><strong>How to detect AJAX Requests</strong></p>
<p>A lot of people are doing things like say this:</p>
<pre class="brush: php;">
if($this-&gt;_request-&gt;getQuery('ajax') == 1)
{
	// Some code
	$data = array(1,2,3,4);
	$this-&gt;_helper-&gt;json($data);&lt;/pre&gt;
}
</pre>
<p>You can actually do this instead:</p>
<pre class="brush: php;">
if ($this-&gt;getRequest()-&gt;isXmlHttpRequest())
{
	// Some code
	$data = array(1,2,3,4);
	$this-&gt;_helper-&gt;json($data);
}
</pre>
<p>In both cases after we use the json helper which will send json data back to the users browser.  This can be really powerful where you can have the same action handle several different types of requests depending on browser capability with very little code replication.  So for example our users can turn javascript features on or off.  On the listing page action it has three different exit points.  One where it just renders a plain table for the javascript table to render.  The other is for when it&#8217;s a xml http request and the third is when the user has javascript disabled.  The last two actually use the same PHP code except for the non javascript uses a different view while the json version sends it back as json.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hawkhost.com/2009/11/21/ajax-zend-framework-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework 1.6 Released</title>
		<link>http://blog.hawkhost.com/2008/09/02/zend-framework-16-released/</link>
		<comments>http://blog.hawkhost.com/2008/09/02/zend-framework-16-released/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 04:06:41 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.hawkhost.com/blog/?p=136</guid>
		<description><![CDATA[Zend Framework 1.6 was just released and we already have it on all our servers.  I can honestly say I did not have time to play around with the release candidate versions so my knowledge of it is not great.  I am however as I write this working on porting our website to use Zend [...]]]></description>
			<content:encoded><![CDATA[<p>Zend Framework 1.6 was just released and we already have it on all our servers.  I can honestly say I did not have time to play around with the release candidate versions so my knowledge of it is not great.  I am however as I write this working on porting our website to use Zend Framework 1.6.  This basically means I need to drop in the new folder and confirm the smarty view system works fine which it does!  I&#8217;ve actually already found one use for it which is the Zend_Service_ReCaptcha functionality as it is the quickest solution.  Our site currently makes use of it using an outside library I&#8217;m assuming (Cody setup the captcha).  Here&#8217;s a quick run down of how easy this is to implement:</p>
<pre class="brush: php;">

$recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
</pre>
<p>Putting in our pubKey and privKey obviously.  Then from there to display it all I need to do is:</p>
<pre class="brush: php;">
$this-&gt;view-&gt;captcha = $recaptcha-&gt;getHTML();
</pre>
<p>Obviously I assigned it to my view but you could just print it if you wanted to.</p>
<pre class="brush: php;">
$result = $recaptcha-&gt;verify(
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);
if (!$result-&gt;isValid()) {
// Failed validation
}
</pre>
<p>It&#8217;s just that easy <img src='http://blog.hawkhost.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here&#8217;s a quick run down of some of the other features:</p>
<ul>
<li>Zend_Tool</li>
<li>Lucene 2.3 Index File Format Support</li>
<li>Zend_Session save handler for Database Tables</li>
<li>Paginator Component</li>
<li>Figlet Support</li>
<li>ReCaptcha Service</li>
<li>Captcha Form Element</li>
<li>Zend_Config_Xml Attribute Support</li>
<li>Zend_File_Transfer Component</li>
<li>File Upload Form Element</li>
<li>Zend_Wildfire Component with FireBug Log Writer</li>
</ul>
<p>There are some useful features there like the Captcha one I mentioned.  The other big one I&#8217;ll probably make use of in the near future is the paginator.  I have my own one I created, but I figure no point reinventing the wheel so switching to use the Zend one makes sense.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hawkhost.com/2008/09/02/zend-framework-16-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Always Have an Order By</title>
		<link>http://blog.hawkhost.com/2008/08/14/always-have-an-order-by/</link>
		<comments>http://blog.hawkhost.com/2008/08/14/always-have-an-order-by/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 20:34:29 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.hawkhost.com/blog/?p=125</guid>
		<description><![CDATA[Yesterday there was a report of a strange bug by a user on a system I&#8217;m currently working with.  I was told a specific row was not showing up in the data set.  The system was using PostgreSQL for the database and used ExtJS grid component to render the data set so my first instinct [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday there was a report of a strange bug by a user on a system I&#8217;m currently working with.  I was told a specific row was not showing up in the data set.  The system was using PostgreSQL for the database and used ExtJS grid component to render the data set so my first instinct was the user was not paging to the next set of data.  To my surprise even when paging I was unable to find the data as well.  I was really confused on this one so I decided to throw the query into my trusty SQL editor and see what is going on.  The first thing I did was remove the limit and offset portions of the query as I had no interest in paging.  To my surprise the entry did in fact show up when I ran it without the limit and offset.  When I ran the query with a limit and a offset and paged through each page I could not find this row.</p>
<p>I was really confused now and to add to my confusion ExtJS was set to do sorting on the ID field of the dataset once the data arrived.  Yet the data itself did not do any sorting so it came back sort of out of place but not entirely.  So I then decided to add an ORDER BY to the statement just so the result would turn up on the first page and sure enough it did.</p>
<p>The reason for this is if you do not set an ORDER BY the database determines how to sort it.  Now usually this is fine if you have one table it&#8217;ll end up sorting by the order the data came into the database which usually means it&#8217;ll be ordered by the primary key.  This data set however joined several tables and did some sub queries.  So with the changing of the offset on the query resulted in the query planner changing how it was sorting the data set or at least that&#8217;s my theory.  It seems strange for it to do it but if you play around with a query analyzer for a bit some times you can see very different ways of putting a query together depending on just a few small changes in the query that you&#8217;d think would not result in any changes in how the data is put together.</p>
<p>So my tip to everyone righting queries make a habit of putting an order by statement in no matter how simple the query may be.  You may get logical results on simple queries but as they become more complicated the sorting may start to become unpredictable especially when you&#8217;re using offset or limit clauses.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hawkhost.com/2008/08/14/always-have-an-order-by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database Table Field Naming Conventions</title>
		<link>http://blog.hawkhost.com/2008/07/04/database-table-field-naming-conventions/</link>
		<comments>http://blog.hawkhost.com/2008/07/04/database-table-field-naming-conventions/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 19:07:41 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.hawkhost.com/blog/?p=97</guid>
		<description><![CDATA[It&#8217;s another day so it&#8217;s time for another rant about something that continues to bug me.
The naming conventions of fields in tables of a database!  There seems to be absolutely no consistency between applications and in some cases even within the application it self.   My biggest gripe I would have to say is the naming [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s another day so it&#8217;s time for another rant about something that continues to bug me.</p>
<p>The naming conventions of fields in tables of a database!  There seems to be absolutely no consistency between applications and in some cases even within the application it self.   My biggest gripe I would have to say is the naming of the primary key&#8217;s and foreign keys of tables.  I&#8217;ve seen the following recently in applications that have say the table customers</p>
<p>id<br />
cid<br />
custid<br />
customer_id</p>
<p>I personally prefer the customer_id for the primary key but even consistency of one naming would be great.  The big reason I like using tablename_id  for the primary key is when joining other tables.  For example:</p>
<pre class="brush: sql;">SELECT * FROM customers c
JOIN orders o ON c.customer_id = o.customer_id</pre>
<p>I like this much better than having something like:</p>
<pre class="brush: sql;">SELECT * FROM customers c
JOIN orders o ON c.id = o.customer_id</pre>
<p>But this I can live with.  It&#8217;s when applications have no consistency what so ever.  They name the primary key &#8220;cid&#8221; for example then the foreign key is &#8220;cust_id&#8221; in one table and &#8220;customer_id&#8221; in another.</p>
<p>This can also be applied to pretty much all fields across all tables.  Some maybe are &#8220;tablename_field&#8221; while others are just &#8220;field&#8221;.  Pick one or the other in an application and if there are multiple developers it might be a good idea to come up with a convention that everyone follows.  But I doubt the developers could come to an agreement anyways I know from experience with an instance where the naming of a common foreign key in an application is still not consistent through out the application.  It is in the database, however the variable name for it seems to change from page to page with some using camel case on it while others believing it should be just one word.</p>
<p>Anyways I&#8217;m sure there are naming conventions somewhere that everyone is suppose to follow for these sort of things but no one seems to do it.  It also does not help that programmers constantly have a change of heart part way through resulting in the continued inconsistency.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hawkhost.com/2008/07/04/database-table-field-naming-conventions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
