<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>William Graham's blog</title>
	<atom:link href="http://liamgraham.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://liamgraham.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<pubDate>Thu, 03 Jul 2008 21:48:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>Adding support for Oracle&#8217;s bitmap indexes to Rails migrations</title>
		<link>http://liamgraham.wordpress.com/2008/07/01/adding-support-for-oracles-bitmap-indexes-to-rails-migrations/</link>
		<comments>http://liamgraham.wordpress.com/2008/07/01/adding-support-for-oracles-bitmap-indexes-to-rails-migrations/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 21:29:57 +0000</pubDate>
		<dc:creator>liamgraham</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://liamgraham.wordpress.com/?p=11</guid>
		<description><![CDATA[As I posted here, my coworker Greg Donald helped me find a way to override the way Rails migrations create Oracle sequences by putting code in the environment.rb file. I mentioned at the bottom of that post that I would like to find a way to make it also support Oracle&#8217;s bitmap indexes. This turned [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As I posted <a href="http://liamgraham.wordpress.com/2008/07/01/fixing-rails-bizarre-approach-to-creating-oracle-sequences/">here</a>, my coworker <a href="http://destiney.com/">Greg Donald</a> helped me find a way to override the way Rails migrations create Oracle sequences by putting code in the environment.rb file. I mentioned at the bottom of that post that I would like to find a way to make it also support Oracle&#8217;s bitmap indexes. This turned out to be trivial, simply a matter of adding another section to the override code I already had. The method which creates the indexes is ActiveRecord::ConnectionAdapters::SchemaStatements.add_index. It surprises me that there isn&#8217;t an Oracle-specific override in the OracleAdapter. Anyway, my code from the last blog post already had the ActiveRecord::ConnectionAdapters in scope, so I added another section as below:</p>
<pre>
module SchemaStatements
&nbsp;&nbsp;def add_index(table_name, column_name, options = })
&nbsp;&nbsp;&nbsp;&nbsp;column_names = Array(column_name)
&nbsp;&nbsp;&nbsp;&nbsp;index_name   = index_name(table_name, :column =&gt; column_names)

&nbsp;&nbsp;&nbsp;&nbsp;if Hash === options # legacy support, since this param was a string
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index_type = options[:unique] ? "UNIQUE" : options[:bitmap] ? "BITMAP" : ""
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index_name = options[:name] || index_name
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index_type = options
&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ")
&nbsp;&nbsp;&nbsp;&nbsp;execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{quoted_column_names})"
&nbsp;&nbsp;end
end
</pre>
<p>Only one change was made to the original:</p>
<pre>index_type = options[:unique] ? "UNIQUE" : ""</pre>
<p>became</p>
<pre>index_type = options[:unique] ? "UNIQUE" : options[:bitmap] ? "BITMAP" : ""</pre>
<p>This now allows the specification of a bitmap option to add_index in the migration file:</p>
<pre>add_index "mytable", ["mycolumn"], :name =&gt; "mytable_bitmap_idx", :bitmap =&gt; true</pre>
<p>I&#8217;m pretty happy with the ability Ruby on Rails gives you to customize things like this. Being able to override class methods in this way is really pretty special.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/liamgraham.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/liamgraham.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/liamgraham.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/liamgraham.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/liamgraham.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/liamgraham.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/liamgraham.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/liamgraham.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/liamgraham.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/liamgraham.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/liamgraham.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/liamgraham.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=liamgraham.wordpress.com&blog=1005477&post=11&subd=liamgraham&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://liamgraham.wordpress.com/2008/07/01/adding-support-for-oracles-bitmap-indexes-to-rails-migrations/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/liamgraham-128.jpg" medium="image">
			<media:title type="html">liamgraham</media:title>
		</media:content>
	</item>
		<item>
		<title>Altering the way Rails migrations create Oracle sequences</title>
		<link>http://liamgraham.wordpress.com/2008/07/01/fixing-rails-bizarre-approach-to-creating-oracle-sequences/</link>
		<comments>http://liamgraham.wordpress.com/2008/07/01/fixing-rails-bizarre-approach-to-creating-oracle-sequences/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 19:04:43 +0000</pubDate>
		<dc:creator>liamgraham</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://liamgraham.wordpress.com/?p=9</guid>
		<description><![CDATA[Lately I&#8217;ve been using Ruby on Rails for a project at work, and am really enjoying it. Several things bug me about managing an Oracle database with migrations, though. The main one that just struck me as bizarre is how each table&#8217;s sequence is created with a starting value of 10,000. Why? Where did that [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Lately I&#8217;ve been using Ruby on Rails for a <a href="http://rewriteproject.com/">project at work</a>, and am really enjoying it. Several things bug me about managing an Oracle database with migrations, though. The main one that just struck me as bizarre is how each table&#8217;s sequence is created with a starting value of 10,000. Why? Where did that number come from, who came up with it, and why is there not a way to override it within the migration, short of using execute to drop the sequence after the fact and recreate it (since you can&#8217;t change an Oracle sequence&#8217;s starting value with an alter statement).</p>
<p>I dug into the code for the OracleAdapter, and sure enough, there it is, right there in the create_table method:</p>
<pre>def create_table(name, options = {}) #:nodoc:
  super(name, options)
  seq_name = options[:sequence_name] || "#{name}_seq"
  execute "CREATE SEQUENCE #{seq_name} START WITH 10000" unless options[:id] == false
end</pre>
<p>I was all set to just modify the CREATE SEQUENCE code above when my coworker <a href="http://destiney.com">Greg Donald</a>, who knows much more about Ruby and RoR than I do, knocked me out with yet another in the long line of things about Ruby on Rails that make me yell &#8220;Sweet!&#8221; Thanks, Greg!</p>
<p>Within your Rails app&#8217;s environment.rb file you can override code. Simply by putting this snippet at the bottom of the file, I was able to change the way migrate creates my Oracle sequences:</p>
<pre>module ActiveRecord
  module ConnectionAdapters
    class OracleAdapter
      def create_table(name, options = {}) #:nodoc:
        super(name, options)
        seq_name = options[:sequence_name] || "#{name}_seq"
        execute "CREATE SEQUENCE #{seq_name} START WITH 1 NOCACHE" unless options[:id] == false
      end
    end
  end
end</pre>
<p>Notice that I also added in <em>NOCACHE</em> while I was at it, to prevent Oracle from grabbing 20 sequence values at a time.</p>
<p>This is just cool. Without having to keep track of custom changes made to the adapter, which could be lost with future upgrades, and without having to resort to a bunch of <em>execute</em> statements within the migration file to drop and recreate the sequences, I&#8217;m able to get the custom behavior that I need. Honestly, of course, I think that the starting value should default to 1, not 10000, and I wish that something like NOCACHE was an option that could be passed. But this gets me what I need, and I can see this sort of override capability coming in very handy for other Rails customizations.</p>
<p>Now on to adding something to support bitmap indexes!  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/liamgraham.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/liamgraham.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/liamgraham.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/liamgraham.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/liamgraham.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/liamgraham.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/liamgraham.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/liamgraham.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/liamgraham.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/liamgraham.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/liamgraham.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/liamgraham.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=liamgraham.wordpress.com&blog=1005477&post=9&subd=liamgraham&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://liamgraham.wordpress.com/2008/07/01/fixing-rails-bizarre-approach-to-creating-oracle-sequences/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/liamgraham-128.jpg" medium="image">
			<media:title type="html">liamgraham</media:title>
		</media:content>
	</item>
		<item>
		<title>Ajax 101 tutorial updated for Zend Framework v1.5</title>
		<link>http://liamgraham.wordpress.com/2008/04/15/ajax-101-tutorial-updated-for-zend-framework-v15/</link>
		<comments>http://liamgraham.wordpress.com/2008/04/15/ajax-101-tutorial-updated-for-zend-framework-v15/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 15:35:22 +0000</pubDate>
		<dc:creator>liamgraham</dc:creator>
		
		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Web Development]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://liamgraham.wordpress.com/?p=8</guid>
		<description><![CDATA[I&#8217;ve updated the Ajax 101 tutorial for version 1.5 of Zend Framework. At some point after I originally wrote it, the Zend Framework team removed a loophole that I and apparently many others mistakenly relied on, relating to resolution of action names. In the original version of this tutorial, I had the javascript making an [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve updated the Ajax 101 tutorial for version 1.5 of Zend Framework. At some point after I originally wrote it, the Zend Framework team removed a loophole that I and apparently many others mistakenly relied on, relating to resolution of action names. In the original version of this tutorial, I had the javascript making an Ajax call to <em><strong>&#8216;index/getData&#8217;</strong></em>, which was resolving to the getDataAction method in the index controller. However, as of version 1.5 of the framework, the case is not getting preserved, so that my &#8216;<strong>getData</strong>&#8216; was getting converted to lowercase &#8216;<strong>getdata</strong>&#8216;, resulting in the error that Ernesto commented about way back in February:</p>
<blockquote><p>Fatal error: Uncaught exception ‘Zend_Controller_Action_Exception’ with message ‘IndexController::getdataAction() does not exist and was not trapped in __call()’</p></blockquote>
<p>Basically, what needs to happen is that there needs to be a word separator in the action name in the javascript so that the framework really knows how to camelcase it, such as <em><strong>&#8216;index/get-data&#8217;.</strong></em> I have edited the blog post and the zipped code to correct this. For an in-depth discussion of this issue, and the team&#8217;s reasoning for blocking the loophole, see the manual here: http://framework.zend.com/manual/en/zend.controller.migration.html</p>
<p>Sorry for any problems people have been seeing!</p>
<p>-william</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/liamgraham.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/liamgraham.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/liamgraham.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/liamgraham.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/liamgraham.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/liamgraham.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/liamgraham.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/liamgraham.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/liamgraham.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/liamgraham.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/liamgraham.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/liamgraham.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=liamgraham.wordpress.com&blog=1005477&post=8&subd=liamgraham&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://liamgraham.wordpress.com/2008/04/15/ajax-101-tutorial-updated-for-zend-framework-v15/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/liamgraham-128.jpg" medium="image">
			<media:title type="html">liamgraham</media:title>
		</media:content>
	</item>
		<item>
		<title>Ajax 101: A Simple Example of Using Ajax with the Zend Framework</title>
		<link>http://liamgraham.wordpress.com/2007/08/06/ajax-101-a-simple-example-of-using-ajax-with-the-zend-framework/</link>
		<comments>http://liamgraham.wordpress.com/2007/08/06/ajax-101-a-simple-example-of-using-ajax-with-the-zend-framework/#comments</comments>
		<pubDate>Mon, 06 Aug 2007 18:14:37 +0000</pubDate>
		<dc:creator>liamgraham</dc:creator>
		
		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Web Development]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://liamgraham.wordpress.com/2007/08/06/ajax-101-a-simple-example-of-using-ajax-with-the-zend-framework/</guid>
		<description><![CDATA[NOTE: I&#8217;ve updated this tutorial for version 1.5 of Zend Framework. At some point after I originally wrote this, the Zend Framework team removed a loophole that I and apparently many others mistakenly relied on, relating to resolution of action names. In the original version of this tutorial, I had the javascript making an Ajax [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>NOTE: </strong>I&#8217;ve updated this tutorial for version 1.5 of Zend Framework. At some point after I originally wrote this, the Zend Framework team removed a loophole that I and apparently many others mistakenly relied on, relating to resolution of action names. In the original version of this tutorial, I had the javascript making an Ajax call to <em><strong>&#8216;index/getData&#8217;</strong></em>, which was resolving to the getDataAction method in the index controller. However, as of version 1.5 of the framework, the case is not getting preserved, so that my &#8216;<strong>getData</strong>&#8216; was getting converted to lowercase &#8216;<strong>getdata</strong>&#8216;, resulting in the error that Ernesto commented about way back in February:</p>
<blockquote><p>Fatal error: Uncaught exception ‘Zend_Controller_Action_Exception’ with message ‘IndexController::getdataAction() does not exist and was not trapped in __call()’</p></blockquote>
<p>Basically, what needs to happen is that there needs to be a word separator in the action name in the javascript so that the framework really knows how to camelcase it, such as <em><strong>&#8216;index/get-data&#8217;.</strong></em> I have edited the blog post and the zipped code to correct this. For an in-depth discussion of this issue, and the team&#8217;s reasoning for blocking the loophole, see the manual here: http://framework.zend.com/manual/en/zend.controller.migration.html</p>
<p>Sorry for any problems people have been seeing!</p>
<p>-william</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>I recently needed to port some existing php code which used Ajax over to the Zend Framework. While there are several tutorials out there with lots of details, I didn&#8217;t find a simple example that would just get me started with how to work Ajax calls into the MVC framework architecture. Eventually, I figured things out by referring to several different tutorials and doing a good amount of Googling. I decided it might be useful to have a very simple example of porting an existing Ajax app to the Zend Framework.</p>
<p>Warning: this app is <strong>very</strong> simplistic &#8230; it is solely designed to show minimum &#8216;hello world&#8217; type of Ajax functionality, and how to fit that into the Zend Framework. There are plenty of more advanced tutorials out there, but this can get you started and show you how to make an Ajax call and respond to it with a Zend controller action. To simplify things even further, I&#8217;m using the <a href="http://www.prototypejs.org/">prototype</a> Javascript library, which makes life a lot easier by, among other things, providing a cross-browser means of creating and sending Ajax requests.</p>
<p>Versions: I wrote this against Prototype 1.5.1.1 and Zend Framework 1.0.1 (now updated for ZF  v. 1.5)</p>
<p>Assumptions: I assume this is running on Apache, as I will include some .htaccess files to deal with url rewriting in the Zend version. I assume you&#8217;re familiar with Ajax &#8230; if not, there are tons of tutorials out there available via Google. I also assume you have some basic familiarity with the Zend Framework. If not, I recommend Rob Allen&#8217;s great <a href="http://akrabat.com/zend-framework-tutorial/">introductory tutorial</a>. And if you need to run the tutorial on Oracle instead of Mysql, well, of course, I recommend <a href="http://liamgraham.wordpress.com/2007/06/05/oracle-modifications-for-rob-allens-zend-framework-tutorial/">this blog post</a> &#8230;  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>If you want the code, download the <a href="http://www.geocities.com/wwgtsc/ajax101.zip">2.4MB zip file</a>, which contains both the Zend app (ajax101_zend directory) and the non-Zend app (ajax101 directory). Both directories also contain the version of prototype that I used. Earlier versions of the download also contained Zend Framework v1.0.1, but I removed this at the same time I updated the code to work with ZF v1.5. I wrote the code on Windows, so be aware of that if you have any problems with the files on other platforms &#8230;</p>
<p>Okay, on to the code.  First, the non-Zend version. I created three files (index.html, boxy.css, and server_script.php) and put them in the same directory on my webserver, along with the prototype.js file. Here&#8217;s the index.html, with a couple of Javascript functions to handle the Ajax call and response (we&#8217;ll factor those out to a separate file in the Zend version):</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<blockquote><p>&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.0 Transitional//EN&#8221;&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Ajax 101&lt;/title&gt;<br />
&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;boxy.css&#8221;&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;prototype.js&#8221;&gt;&lt;/script&gt;</p>
<p>&lt;script language=&#8217;javascript&#8217;&gt;</p>
<p>//handle the Ajax response &#8230;<br />
function handleResponse(transport)<br />
{<br />
$(&#8217;hello&#8217;).innerHTML = transport.responseText;<br />
}</p>
<p>//creates a prototype Ajax object, sends a request, and registers the callback function &#8216;handleResponse&#8217;<br />
function callAjax(s)<br />
{<br />
var myAjax = new Ajax.Request(&#8217;server_script.php&#8217;,<br />
{method: &#8216;get&#8217;, parameters: {state: s},<br />
onComplete: handleResponse});<br />
}</p>
<p>&lt;/script&gt;</p>
<p>&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;p&gt;<br />
&lt;span id=&#8217;hover_span&#8217; onmouseover=&#8221;callAjax(&#8217;do&#8217;)&#8221; onmouseout=&#8221;callAjax(&#8217;undo&#8217;)&#8221;&gt; &lt;b&gt;Hover here to trigger Ajax call:&lt;/b&gt; &lt;/span&gt;<br />
&lt;/p&gt;</p>
<p>&lt;span id=&#8217;hello&#8217;&gt; boring pre-Ajax-call text &#8230; &lt;/span&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Here&#8217;s the simple stylesheet used:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<blockquote><p>#hover_span<br />
{<br />
font-size: 12pt;<br />
}</p>
<p>#hover_span:hover<br />
{<br />
cursor: crosshair;<br />
background-color: yellow;<br />
}</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>And here is the php server-side script which simply echoes some text back depending on the &#8217;state&#8217; parameter passed in the request:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<blockquote><p>&lt;?php</p>
<p>$state = $_REQUEST['state'];</p>
<p>if ($state == &#8216;do&#8217;)<br />
{<br />
echo &#8216;&lt;h1&gt;exciting text retrieved from server!&lt;/h1&gt;&#8217;;<br />
}<br />
else if ($state == &#8216;undo&#8217;)<br />
{<br />
echo &#8216;reset to boring &#8230;&#8217;;<br />
}<br />
else<br />
{<br />
echo &#8216;unknown state parameter passed to server!!&#8217;;<br />
}</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>So, if you trace through what happens, when you hover over the text at the top of the index.html page, <strong>Hover here to trigger Ajax call</strong>, the <em>mouseover</em> event fires, sending an Ajax request with a &#8217;state&#8217; parameter of &#8216;do&#8217; to the server. The server responds with the text <strong>exciting text retrieved from server!</strong> enclosed in <strong>h1</strong> tags. When the mouse leaves the text at the top of the page, the <em>mouseout</em> event fires, sending an Ajax request with a &#8217;state&#8217; parameter of &#8216;undo&#8217; to the server, which responds with the text <strong>reset to boring &#8230;</strong></p>
<p>Pretty simple, nothing exciting or difficult &#8230; just a super-basic example of doing something with Ajax. Okay, so how do we move that into the Zend Framework?</p>
<p>The first thing that is going to change is the directory structure. As I mentioned, for the simple &#8216;Ajax 101&#8242; app, I just put all the files in the same directory on my webserver. For Zend, I&#8217;m going to need to separate things out, which is a good thing. I&#8217;m following a typical Zend Framework directory structure here, so it will look like this:</p>
<p>docroot<br />
&#8211;app<br />
&#8212;-controllers<br />
&#8212;-views<br />
&#8212;&#8212;scripts<br />
&#8211;library<br />
&#8211;public<br />
&#8212;-scripts<br />
&#8212;-styles</p>
<p>You may have noticed the lack of a model directory. That&#8217;s because in this very simplistic example, there are no models.</p>
<p>Okay, so what next? Well, first we need to install the framework. Download the latest version of the <a href="http://framework.zend.com/">framework</a> (I used v1.5.1 in the latest work I did on this). Once you&#8217;ve extracted it, copy the library/Zend directory to your docroot/library directory.</p>
<p>Next we need a bootstrap file for the framework. This will be pretty simple for this example, since we&#8217;re not doing much, so we won&#8217;t be loading a bunch of Zend classes, setting up database connections, etc. All we&#8217;ll really be doing is some basic settings, like error reporting, include paths, and setting up the controller. This is in the index.php file in the docroot:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>&lt;?php</p>
<blockquote><p>error_reporting(E_ALL | E_STRICT);<br />
date_default_timezone_set(&#8217;America/Chicago&#8217;);</p>
<p>set_include_path(&#8217;.&#8217; . PATH_SEPARATOR . &#8216;./library&#8217; . PATH_SEPARATOR . get_include_path());</p></blockquote>
<blockquote><p>include &#8220;Zend/Loader.php&#8221;;</p>
<p>//setup controller<br />
Zend_Loader::loadClass(&#8217;Zend_Controller_Front&#8217;);<br />
$frontController = Zend_Controller_Front::getInstance();<br />
$frontController-&gt;throwExceptions(true);<br />
$frontController-&gt;setControllerDirectory(&#8217;./app/controllers&#8217;);</p>
<p>//run<br />
$frontController-&gt;dispatch();</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Next we&#8217;ll set up a simple controller, and put the code that was in the server_script.php file inside a controller action. This is the IndexController.php file in the docroot/app/controllers directory:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<blockquote><p>&lt;?php</p>
<p>class IndexController extends Zend_Controller_Action<br />
{<br />
function init()<br />
{<br />
$this-&gt;initView();<br />
$this-&gt;view-&gt;baseUrl = $this-&gt;_request-&gt;getBaseUrl();<br />
Zend_Loader::loadClass(&#8217;Zend_Debug&#8217;);<br />
}</p>
<p>function indexAction()<br />
{<br />
//echo &#8220;&lt;p&gt;in IndexController::indexAction()&lt;/p&gt;&#8221;;<br />
$this-&gt;view-&gt;title = &#8220;Zend Ajax 101&#8243;;<br />
}</p>
<p>function getDataAction()<br />
{<br />
$this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender();</p>
<p>$state = $_REQUEST['state'];</p>
<p>if ($state == &#8216;do&#8217;)<br />
{<br />
echo &#8216;&lt;h1&gt;exciting text retrieved from server!&lt;/h1&gt;&#8217;;<br />
}<br />
else if ($state == &#8216;undo&#8217;)<br />
{<br />
echo &#8216;reset to boring &#8230;&#8217;;<br />
}<br />
else<br />
{<br />
echo &#8216;unknown state parameter passed to server!!&#8217;;<br />
}<br />
}<br />
}</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>The only difference between our initial php script and the code in the getDataAction() method is the crucial first line:</p>
<blockquote><p>$this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender();</p></blockquote>
<p>This tells Zend that this particular action method is not going to result in the re-rendering of the view.</p>
<p>Next, here&#8217;s our index.phtml, which is just slightly altered from the index.html of the non-Zend app, and is saved in the docroot/app/views/scripts/index directory:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<blockquote><p>&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.0 Transitional//EN&#8221;&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;&lt;?php echo $this-&gt;title ?&gt;&lt;/title&gt;<br />
&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;public/styles/boxy.css&#8221;&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;public/scripts/prototype.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;public/scripts/ajax_funcs.js&#8221;&gt;&lt;/script&gt;</p>
<p>&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;p&gt;<br />
&lt;span id=&#8217;hover_span&#8217; onmouseover=&#8221;callAjax(&#8217;do&#8217;)&#8221; onmouseout=&#8221;callAjax(&#8217;undo&#8217;)&#8221;&gt; &lt;b&gt;Hover here to trigger Ajax call:&lt;/b&gt; &lt;/span&gt;<br />
&lt;/p&gt;</p>
<p>&lt;span id=&#8217;hello&#8217;&gt; boring pre-Ajax-call text &#8230; &lt;/span&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>You&#8217;ll notice that we&#8217;ve factored the javascript functions out to a separate file, as I said we would do. Here is that file, docroot/public/scripts/ajax_funcs.js:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<blockquote><p>//handle the Ajax response &#8230;<br />
function handleResponse(transport)<br />
{<br />
$(&#8217;hello&#8217;).innerHTML = transport.responseText;<br />
}</p>
<p>//creates a prototype Ajax object, sends a request, and registers the callback function &#8216;handleResponse&#8217;<br />
function callAjax(s)<br />
{</p>
<p>//remember to put a word separator between elements of the camelcase action name, per the ZF manual:<br />
var myAjax = new Ajax.Request(&#8217;index/get-data&#8217;,<br />
{method: &#8216;get&#8217;, parameters: {state: s},<br />
onComplete: handleResponse});<br />
}</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>The stylesheet is the same as the previous app, so I won&#8217;t repeat it here. Just note that it is saved in docroot/public/styles.</p>
<p>Finally, there are some .htaccess files we&#8217;ll need, since we need to handle rewrite rules and exceptions. In the docroot, here&#8217;s what you need in your .htaccess:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<blockquote><p>RewriteEngine on<br />
RewriteCond %{REQUEST_URI} !/public.*</p>
<p>RewriteRule .* index.php</p>
<p>php_flag magic_quotes_gpc off<br />
php_flag register_globals off</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>And for the docroot/public directory:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<blockquote><p>RewriteEngine off</p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Okay, that&#8217;s it! If all has gone well, you should see the same behavior in the Zend Framework version as you did in the non-Zend one. Hopefully, this will give you a jumping off point for more advanced Ajax work with the Zend Framework.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/liamgraham.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/liamgraham.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/liamgraham.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/liamgraham.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/liamgraham.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/liamgraham.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/liamgraham.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/liamgraham.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/liamgraham.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/liamgraham.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/liamgraham.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/liamgraham.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=liamgraham.wordpress.com&blog=1005477&post=7&subd=liamgraham&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://liamgraham.wordpress.com/2007/08/06/ajax-101-a-simple-example-of-using-ajax-with-the-zend-framework/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/liamgraham-128.jpg" medium="image">
			<media:title type="html">liamgraham</media:title>
		</media:content>
	</item>
		<item>
		<title>Oracle modifications for Rob Allen&#8217;s Zend Framework Tutorial</title>
		<link>http://liamgraham.wordpress.com/2007/06/05/oracle-modifications-for-rob-allens-zend-framework-tutorial/</link>
		<comments>http://liamgraham.wordpress.com/2007/06/05/oracle-modifications-for-rob-allens-zend-framework-tutorial/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 21:08:54 +0000</pubDate>
		<dc:creator>liamgraham</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://liamgraham.wordpress.com/2007/06/05/oracle-modifications-for-rob-allens-zend-framework-tutorial/</guid>
		<description><![CDATA[After working with CakePHP, I also decided to give the Zend Framework a try. I initially had some problems with it back at beta 0.9.1, but was told by the DB team lead that many Oracle issues would be fixed by the first release. Well, Zend Framework 1.0.0 Release Candidate 1 is out now, so [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>After working with CakePHP, I also decided to give the Zend Framework a try. I initially had some problems with it back at beta 0.9.1, but was told by the DB team lead that many Oracle issues would be fixed by the first release. Well, Zend Framework 1.0.0 Release Candidate 1 is out now, so I revisited it.</p>
<p>I had chosen the tutorial written by Rob Allen (<a href="http://akrabat.com/" title="Akra" target="_blank">Akra</a>), available <a href="http://akrabat.com/zend-framework-tutorial/" target="_blank">here</a> . This is a very neat and well-maintained tutorial on creating a simple Album / CD tracking system. Below is the DDL to create the database objects, converted to Oracle syntax. Note that, as in the CakePHP tutorial work I did earlier, I&#8217;m mimicing an auto-increment ID by using a before-insert trigger to assign a value from the sequence:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
CREATE TABLE album (<br />
id number(11,0) NOT NULL,<br />
artist varchar2(100) NOT NULL,<br />
title varchar2(100) NOT NULL,<br />
PRIMARY KEY (id)<br />
);</p>
<p>create sequence album_seq<br />
MINVALUE 1<br />
MAXVALUE 999999999999999999999999999<br />
INCREMENT BY 1<br />
START WITH 1<br />
NOCACHE<br />
NOORDER<br />
NOCYCLE ;</p>
<p>CREATE OR REPLACE TRIGGER ALBUM_BEF_UPDATE_TRG<br />
BEFORE INSERT ON ALBUM<br />
FOR EACH ROW<br />
BEGIN<br />
select album_seq.nextval into :new.id from dual;<br />
END;<br />
/</p>
<p>ALTER TRIGGER ALBUM_BEF_UPDATE_TRG ENABLE;</p>
<p>insert into album (artist, title) values (&#8217;James Morrison&#8217;, &#8216;Undiscovered&#8217;);<br />
insert into album (artist, title) values (&#8217;Snow Patrol&#8217;, &#8216;Eyes Open&#8217;);<br />
commit;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Here are the settings to use in your config.ini (Rob, thanks for pointing out that I had initially forgotten to include this!):</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>[general]<br />
db.adapter = Oracle<br />
db.config.host = myDatabaseHostName<br />
db.config.username = myUserName<br />
db.config.password = notGonnaTellYou<br />
db.config.dbname = mySID</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>In addition to the DDL changes, there is some strange behavior due to the fact that Oracle converts all non-quoted database object names to uppercase in the data dictionary. This means that attribute names in your Zend Framework PHP code that refer to column names need to be in uppercase as well. For example, here is an excerpt from _form.phtml from the tutorial:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&lt;label for=&#8221;artist&#8221;&gt;Artist&lt;/label&gt;<br />
escape(trim($this-&gt;album-&gt;artist));?&gt;&#8221;/&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>In order for this to work in Oracle, it needs to be modified so that the &#8216;artist&#8217; attribute is uppercased:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&lt;label for=&#8221;artist&#8221;&gt;Artist&lt;/label&gt;<br />
escape(trim($this-&gt;album-&gt;ARTIST));?&gt;&#8221;/&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>You will need to make this change everywhere that there is a reference to an attribute which maps to an Oracle column name. Just go through the code in the tutorial and uppercase artist, title, and id when they appear as attributes of album. It makes for rather strange-looking code, but it is the only way that I know of to get the Zend Framework and Oracle to work together. Actually, I take that back &#8230; it would probably work if you used quoted identifiers to force Oracle to store lowercase object names, but I hate doing that. It means that anytime you write raw SQL you have to embed database object names in quotes, and it just gets nasty, imho.</p>
<p>One note:<br />
1) DON&#8217;T uppercase <em>album</em> in the above, i.e., don&#8217;t do this: $this-&gt;ALBUM-&gt;ARTIST. In this case, &#8216;album&#8217; is a variable name, not something that needs to map to the Oracle data dictionary. That&#8217;s probably pretty obvious, but I thought I&#8217;d throw it out there anyway, just in case &#8230;</p>
<p>I hope this helps anyone who is trying to get going with Oracle on the Zend Framework. Please contact me with any questions, or post comments. Cheers!<br />
&#8211;William</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/liamgraham.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/liamgraham.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/liamgraham.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/liamgraham.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/liamgraham.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/liamgraham.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/liamgraham.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/liamgraham.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/liamgraham.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/liamgraham.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/liamgraham.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/liamgraham.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=liamgraham.wordpress.com&blog=1005477&post=6&subd=liamgraham&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://liamgraham.wordpress.com/2007/06/05/oracle-modifications-for-rob-allens-zend-framework-tutorial/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/liamgraham-128.jpg" medium="image">
			<media:title type="html">liamgraham</media:title>
		</media:content>
	</item>
		<item>
		<title>Typesafe arrays for PHP</title>
		<link>http://liamgraham.wordpress.com/2007/05/21/typesafe-arrays-for-php/</link>
		<comments>http://liamgraham.wordpress.com/2007/05/21/typesafe-arrays-for-php/#comments</comments>
		<pubDate>Mon, 21 May 2007 18:16:11 +0000</pubDate>
		<dc:creator>liamgraham</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://liamgraham.wordpress.com/2007/05/21/typesafe-arrays-for-php/</guid>
		<description><![CDATA[PHP is not a strongly typed language. This makes for very convenient and quick coding, but it can also lead to bugs and confusion. I noticed recently that, most likely due to my own paranoia (and Java background), I was checking the types of array elements every time I accessed them, just to make sure [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>PHP is not a strongly typed language. This makes for very convenient and quick coding, but it can also lead to bugs and confusion. I noticed recently that, most likely due to my own paranoia (and Java background), I was checking the types of array elements every time I accessed them, just to make sure I was dealing with ints when I thought I was dealing with ints, etc. I decided that I&#8217;d rather just find a way to make some typesafe array classes to use &#8230; so that&#8217;s what I did.</p>
<p>There is an ArrayObject class in PHP5 which can be subclassed (not sure about PHP4, since I&#8217;m new to PHP and jumped straight into v5.x). If you have an ArrayObject <em>$myArray</em>, there are two ways in which you can append a new element:</p>
<blockquote></blockquote>
<blockquote><p>$myArray-&gt;append($foo);</p></blockquote>
<p>and</p>
<blockquote><p>$myArray[] = $foo;<br />
//<em>or, e.g., $myArray[3] = $foo, if you want to alter the 4th element of the array</em></p></blockquote>
<p>Affecting the behavior of the first one is pretty obvious: override the append method in the subclass, adding type checking. The second one is a little more obscure, and I had to search for a while to find out how to affect the [] operations. I was looking for C++-style operator overloading, where I could somehow define what &#8216;[]&#8216; meant in my class. PHP doesn&#8217;t do this, except for, I believe, in a PECL extension. Finally I found a bulletin board post mentioning that the offsetSet and offsetGet methods of ArrayObject actually control what happens with the square bracket method of array access, so I was set to go.</p>
<p>Initially I wrote four subclasses of ArrayObject: IntArray, FloatArray, StringArray, and BooleanArray, each of which overrode the append and offsetSet methods from the parent class. However, I then did some refactoring, realizing that there was code that could be factored to a base class. So I defined an abstract base class, TypeSafeArray, which looks like this:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<code><br />
/**<br />
* @desc Abstract class extending ArrayObject. Used as base class for<br />
*              type-specific array subclasses. Each subclass must implement<br />
*              the abstract method typeCheck to define its appropriate type<br />
*              checking behavior<br />
*<br />
* @package php_wrappers.arrays<br />
* @author Bill Graham, 20070514<br />
*<br />
*/</code></p>
<p>abstract class TypeSafeArray extends ArrayObject<br />
{<br />
/**<br />
* @desc Overriding ArrayObject::append to add typechecking<br />
* @param mixed $val - a value to append to the array<br />
*/<br />
public function append($val)<br />
{<br />
$this-&gt;typeCheck($val);<br />
parent::append($val);<br />
}</p>
<p>/**<br />
* @desc Overriding ArrayObject::offsetSet to add typechecking; this method is called when values are set using the []<br />
* @param int $idx - the index of the array element to set<br />
* @param mixed $val - the value to set<br />
*/<br />
public function offsetSet($idx, $val)<br />
{<br />
$this-&gt;typeCheck($val);<br />
parent::offsetSet($idx, $val);<br />
}</p>
<p>/**<br />
* @desc abstract method must be implemented by subclasses to define type-checking behavior<br />
* @param mixed $val - the value to be type-checked<br />
*/<br />
abstract protected function typeCheck($val);<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
By doing this, the type-specific arrays can simply extend the TypeSafeArray class, and provide an implementation of the  abstract <em>typeCheck</em> method. As an example, here&#8217;s my IntArray class:</p>
<blockquote><p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>/**<br />
* @desc Array class to specifically hold integer values<br />
*<br />
* @package php_wrappers.arrays<br />
* @author Bill Graham, 20070510<br />
*/</p>
<p>require_once(&#8217;TypeSafeArray.php&#8217;);</p>
<p>class IntArray extends TypeSafeArray<br />
{<br />
/**<br />
* @desc implementation of abstract method from TypeSafeArray to define type-checking behavior<br />
* @param mixed $val - the value to be type-checked<br />
*/<br />
protected function typeCheck($val)<br />
{<br />
if (!is_int($val))<br />
{<br />
throw new Exception(&#8221;Non-integer value &#8216;&#8221; . $val . &#8220;&#8216; supplied to IntArray&#8221;);<br />
}</p>
<p>return true;<br />
}<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p></blockquote>
<p>Any other type-specific array classes will be similar &#8230; simply provide an implementation of the <em>typeCheck</em> method which does whatever is needed to insure that only arguments of the correct type are appended to the array. Below is a simple test script showing the classes in action:</p>
<blockquote><p> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>require_once(&#8217;IntArray.php&#8217;);</p>
<p>$set = new IntArray();</p>
<p>try<br />
{<br />
//legal operations. these should succeed &#8230;<br />
$set-&gt;append(1);<br />
$set[] = 2;<br />
$set[2] = 3;</p>
<p>//illegal operations. each will throw an exception. uncomment any line you want to try &#8230;<br />
$set-&gt;append(1.2);<br />
//$set[] = &#8220;foo&#8221;;<br />
//$set[2] = 3.2;<br />
}<br />
catch (Exception $e)<br />
{<br />
print &#8220;Exception encountered appending to &#8221; . get_class($set) . &#8220;:\n&#8221;;<br />
print &#8220;\t&#8221; . $e-&gt;getMessage() . &#8220;\n&#8221;;<br />
}</p>
<p>foreach($set as $val)<br />
{<br />
print $val . &#8220;\n&#8221;;<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p></blockquote>
<p>Okay, there we go. I find these classes to be very useful. I may be in the minority, but I really do want type safety as an option for my PHP development.</p>
<p>Finally, I certainly don&#8217;t claim to be the only person, or the first person who has thought of this. I didn&#8217;t run across any others in my searches, although I did find a few similar things more focused on &#8216;collection&#8217; classes. I&#8217;d love to know of other solutions or implementations, so email me or post a comment. Thanks!</p>
<p>-William</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/liamgraham.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/liamgraham.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/liamgraham.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/liamgraham.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/liamgraham.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/liamgraham.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/liamgraham.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/liamgraham.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/liamgraham.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/liamgraham.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/liamgraham.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/liamgraham.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=liamgraham.wordpress.com&blog=1005477&post=5&subd=liamgraham&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://liamgraham.wordpress.com/2007/05/21/typesafe-arrays-for-php/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/liamgraham-128.jpg" medium="image">
			<media:title type="html">liamgraham</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Oracle with CakePHP: 15 Minute Blog Tutorial</title>
		<link>http://liamgraham.wordpress.com/2007/04/19/using-oracle-with-cakephp-15-minute-blog-tutorial/</link>
		<comments>http://liamgraham.wordpress.com/2007/04/19/using-oracle-with-cakephp-15-minute-blog-tutorial/#comments</comments>
		<pubDate>Thu, 19 Apr 2007 21:39:02 +0000</pubDate>
		<dc:creator>liamgraham</dc:creator>
		
		<category><![CDATA[CakePHP]]></category>

		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://liamgraham.wordpress.com/2007/04/19/using-oracle-with-cakephp-15-minute-blog-tutorial/</guid>
		<description><![CDATA[As I mentioned in my &#8216;About Me&#8217; page, I&#8217;m fairly new to PHP, having been primarily a Java guy for the last 10 years. Having used or investigated several of the webapp frameworks from the Java world (Struts, Stripes, Spring), when I found myself needing to program in PHP, I naturally looked around for a [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As I mentioned in my &#8216;About Me&#8217; page, I&#8217;m fairly new to PHP, having been primarily a Java guy for the last 10 years. Having used or investigated several of the webapp frameworks from the Java world (<a href="http://struts.apache.org/">Struts</a>, <a href="http://mc4j.org/confluence/display/stripes/Home">Stripes</a>, <a href="http://www.springframework.org/">Spring</a>), when I found myself needing to program in PHP, I naturally looked around for a good MVC framework. There are several out there, as most of you no doubt know. The one that has really got me interested right now is <a href="http://www.cakephp.org/">CakePHP</a>. I think the thing I&#8217;m most impressed with about it is the &#8216;convention over configuration&#8217; philosophy that I believe it takes from Rails. Having seen how configuration-heavy Struts and Spring are in the Java world, this really was a breath of fresh air.</p>
<p>One thing that initially concerned me, though, is that there isn&#8217;t an Oracle driver currently released for Cake. This led me to find Jeff Loiselle&#8217;s <a href="http://jeff.loiselles.com/wordpress/?p=20" title="dbo_oracle driver">dbo_oracle driver</a>. While it&#8217;s not in the current release, it seems to be pretty mature, and I&#8217;ve started to use it as I learn the framework.  Actually, I&#8217;ve &#8216;translated&#8217; the DDL for some of the easy tutorials from MySQL syntax to Oracle syntax. If anyone is interested below is the Oracle DDL for the <a href="http://manual.cakephp.org/appendix/blog_tutorial">15 Minute Blog Tutorial</a>. My apologies if someone has already done this! Please let me know, and I&#8217;ll give proper credit to whoever did it first. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>First, You&#8217;ll need to get the dbo_oracle driver from the link to Jeff&#8217;s blog that I posted above, where he gives the url to his svn trunk. Save it to your cake/libs/model/dbo directory along with all the other database drivers. Next, you&#8217;ll need to configure Cake to connect to Oracle. Here&#8217;s a sample entry for Oracle in the /app/config/database.php file:</p>
<pre>
----------------------------------------------------------
var $default = array('driver' =&gt; 'oracle',
 			'connect' =&gt; 'oci_connect',
			'host' =&gt; 'mypcname.Vanderbilt.edu',
			'login' =&gt; 'mylogin',
			'password' =&gt; 'notgonnatellyou',
			'database' =&gt; 'mySID',
			'prefix' =&gt; '');
----------------------------------------------------------</pre>
<p>Now here&#8217;s the DDL in Oracle syntax for creating the POSTS table and inserting the three initial rows. Also notice that I&#8217;m mimicing the MySQL autoincrement by using an Oracle sequence and a before insert trigger to populate the &#8216;id&#8217; value:</p>
<pre>
----------------------------------------------------------
CREATE TABLE POSTS
( ID NUMBER,
  TITLE VARCHAR2(50),
  BODY VARCHAR2(4000),
  CREATED DATE,
  MODIFIED DATE,
   PRIMARY KEY (ID)
);

CREATE SEQUENCE POSTS_SEQ
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  INCREMENT BY 1
  START WITH 1
  NOCACHE
  NOORDER
  NOCYCLE ;

CREATE OR REPLACE TRIGGER POSTS_BEF_UPDATE_TRG
BEFORE INSERT ON POSTS
FOR EACH ROW
BEGIN
      select posts_seq.nextval into :new.id from dual;
END;
/
ALTER TRIGGER POSTS_BEF_UPDATE_TRG ENABLE;

INSERT INTO POSTS (TITLE, BODY, CREATED) VALUES ('The title', 'This is the post body.', SYSDATE);
INSERT INTO POSTS (TITLE, BODY, CREATED) VALUES ('A title once again', 'And the post body follows.', SYSDATE);
INSERT INTO POSTS (TITLE, BODY, CREATED) VALUES ('Title strikes back', 'This is really exciting! Not.', SYSDATE);

commit;
----------------------------------------------------------</pre>
<p>Okay, the above info basically corresponds to sections 3 and 4 of the tutorial. With that, you should be set up to do the rest of the tutorial on Oracle instead of MySQL. Enjoy, and please let me know if you have any problems with this. It works for me, but I know that doesn&#8217;t guarantee anything for you &#8230;  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>-William</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/liamgraham.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/liamgraham.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/liamgraham.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/liamgraham.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/liamgraham.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/liamgraham.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/liamgraham.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/liamgraham.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/liamgraham.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/liamgraham.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/liamgraham.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/liamgraham.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=liamgraham.wordpress.com&blog=1005477&post=3&subd=liamgraham&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://liamgraham.wordpress.com/2007/04/19/using-oracle-with-cakephp-15-minute-blog-tutorial/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/liamgraham-128.jpg" medium="image">
			<media:title type="html">liamgraham</media:title>
		</media:content>
	</item>
	</channel>
</rss>