<?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>Ricky Stevens Web Development Blog</title>
	<atom:link href="http://blog.ricky-stevens.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ricky-stevens.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Sun, 30 Oct 2011 20:15:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Zend Framework &#8211; Get The Module, Controller and Action by Route Name</title>
		<link>http://blog.ricky-stevens.com/zend-framework-module-controller-action-from-route-name/</link>
		<comments>http://blog.ricky-stevens.com/zend-framework-module-controller-action-from-route-name/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 10:27:19 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Backend Development]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=344</guid>
		<description><![CDATA[The context of this is actually for ACL, where I wanted to determine whether a use can view the link or not. I have seen other people extend the URL View Helper to do this which kind of works, but it just means the entire &#60;a&#62; tag has to be produced by the helper rather [...]]]></description>
			<content:encoded><![CDATA[<p>The context of this is actually for <strong>ACL</strong>, where I wanted to determine whether a use can view the link or not. I have seen other people extend the <strong>URL View Helper</strong> to do this which kind of works, but it just means the entire &lt;a&gt; tag has to be produced by the helper rather than the URL. This didn&#8217;t sit too well with me, so I settled for wrapping the &lt;a&gt; in a IF block. Within my templates I only use the <strong>route name</strong>, i don&#8217;t pass through the <strong>module</strong>/<strong>controller</strong>/<strong>action</strong> params to the URL helper, as it means refactoring <strong>modules</strong> and <strong>controllers</strong> is much easier, if the need were to arise. Due to this, I needed to fetch the <strong>Module name</strong>, <strong>Controller Name</strong> and <strong>Action name</strong> from the <strong>Route name</strong>. Simple eh?</p>
<p><span id="more-344"></span></p>
<p>Well, yes and no. The solution is very simple, and hardly worth blogging. But google turned up NOTHING for this. I spent a good 20 minutes googling before giving up and diving into <strong>Zend Frameworks</strong> API Reference. The code to get the <strong>module</strong>, <strong>controller</strong> and <strong>action</strong> from a <strong>route</strong> <strong>name</strong> is;</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="re0">$objRoute</span> <span class="sy0">=</span> Zend_Controller_Front<span class="sy0">::</span><span class="me2">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">getRouter</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="re0">$objRoute</span> <span class="sy0">=</span> &nbsp;<span class="re0">$objRoute</span><span class="sy0">-&gt;</span><span class="me1">getRoute</span><span class="br0">&#40;</span><span class="st_h">'exampleRoute'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2"><a href="http://www.php.net/var_dump"><span class="kw3">var_dump</span></a><span class="br0">&#40;</span> <span class="re0">$objRoute</span><span class="sy0">-&gt;</span><span class="me1">getDefaults</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
</ol></div></div></div>
<p>This would produce the following;</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><div class="text" style="font-family:monospace;"><ol><li class="li1"><div class="de1">array</div></li>
<li class="li1"><div class="de1">&nbsp; 'module' =&gt; string 'default' (length=7)</div></li>
<li class="li1"><div class="de1">&nbsp; 'controller' =&gt; string 'index' (length=5)</div></li>
<li class="li1"><div class="de1">&nbsp; 'action' =&gt; string 'index' (length=5)</div></li>
</ol></div></div></div>
<p>Seems a little too simple, but I couldn&#8217;t find any reference to it.</p>
<div class="su-linkbox" id="post-344-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/zend-framework-module-controller-action-from-route-name/&quot;&gt;Zend Framework &#8211; Get The Module, Controller and Action by Route Name&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/zend-framework-module-controller-action-from-route-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework, Doctrine and APC</title>
		<link>http://blog.ricky-stevens.com/zend-framework-doctrine-apc/</link>
		<comments>http://blog.ricky-stevens.com/zend-framework-doctrine-apc/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 10:40:33 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Backend Development]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=339</guid>
		<description><![CDATA[When using technologies such as Zend Framework and Doctrine, some form of OpCode caching is a must. The average memory used per request with Zend Framework alone is ~30MB, which is a massive performance hit. Doctrine doesn&#8217;t fare much better either. My prefered caching mechanism is APC, but there are certain conflicts it has creates [...]]]></description>
			<content:encoded><![CDATA[<p>When using technologies such as <strong>Zend Framework</strong> and <strong>Doctrine</strong>, some form of <strong>OpCode</strong> caching is a must. The average memory used per request with <strong>Zend Framework</strong> alone is ~30MB, which is a massive performance hit. <strong>Doctrine</strong> doesn&#8217;t fare much better either. My prefered caching mechanism is <strong>APC</strong>, but there are certain conflicts it has creates when using it with these technologies.</p>
<p><span id="more-339"></span></p>
<p>The one I came accross recently was this error;</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><div class="text" style="font-family:monospace;"><ol><li class="li1"><div class="de1">Fatal error: spl_autoload() [function.spl-autoload]: Class Doctrine_Event could not be loaded in /library/Doctrine/Record.php on line 803</div></li>
</ol></div></div></div>
<p>Bit of a bizare one, and had me scratching my head for a good hour or so. It turns out the problem was the way <strong>Zend</strong> and <strong>APC</strong> both use sessions, and they overwrite each others shutdown mechanisms. This then cascades down and causes the <strong>autoloading</strong> problem.</p>
<p>The solution to this is <strong>PHP</strong>&#8216;s <a href="http://php.net/manual/en/function.register-shutdown-function.php" target="_blank"><span style="text-decoration: underline;"><span style="color: #993300;">register_showdown_function()</span></span></a> executes a function on shutdown. With this, you can manually shut down the <strong>Zend Session session</strong> handler, resolving this conflict.</p>
<p>To accomplish this, simply add this method into your application <strong>Bootstrap.php</strong></p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1">protected <span class="kw2">function</span> _initShutdownSession<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/register_shutdown_function"><span class="kw3">register_shutdown_function</span></a><span class="br0">&#40;</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span> <span class="st_h">'Zend_Session'</span><span class="sy0">,</span> <span class="st_h">'writeClose'</span> <span class="br0">&#41;</span><span class="sy0">,</span> <span class="kw4">true</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="br0">&#125;</span></div></li>
</ol></div></div></div>
<p>With this, you should be able to get <strong>APC</strong> up and caching effectively with <strong>Zend Framework</strong> and <strong>Doctrine 1.2</strong>.</p>
<div class="su-linkbox" id="post-339-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/zend-framework-doctrine-apc/&quot;&gt;Zend Framework, Doctrine and APC&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/zend-framework-doctrine-apc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>jQuery Ui Sortable &#8211; Offset Bug</title>
		<link>http://blog.ricky-stevens.com/jquery-sortable-offset-bug/</link>
		<comments>http://blog.ricky-stevens.com/jquery-sortable-offset-bug/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 11:15:37 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Frontend Development]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=328</guid>
		<description><![CDATA[Offset bug with jQuery Ui Sortable when dragging items]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <strong>jQuery Sortable</strong> for quite a while over various projects, and I&#8217;ve never encountered any strange behaviour. On my current project however, I had used the <strong>jQuery</strong> <strong>UI Sortable</strong> to allow the client to re-order some elements within an HTML list. Oddly though, whenever you scrolled down the page to get to the list, and dragged an element, the <strong>offset</strong> of the dragged element went a bit mad and flew up the page!</p>
<p><span id="more-328"></span></p>
<p>After a little of searching and investigating, I found out what was causing this. The front-end development had been done by our Front End Developer, and handed over to myself to work on. Within his generic <strong>CSS</strong> file was the property;</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><div class="css" style="font-family:monospace;"><ol><li class="li1"><div class="de1">overflow-y<span class="sy0">:</span><span class="kw2">scroll</span><span class="sy0">;</span></div></li>
</ol></div></div></div>
<p>He, quite rightly, added this in so on IE browsers, if the content length changed dynamically, the page didn&#8217;t jump when the scrollbar appeared. Removing this properly from the pages stylesheet fixed the <strong>offset bug</strong> with <strong>jQuery</strong> <strong>UI Sortable</strong>.</p>
<p>Not quite sure why, I intend to investigate why this is happening within the coming weeks, but for now I hope posting this will make somebody else&#8217;s life a little easier!</p>
<div class="su-linkbox" id="post-328-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/jquery-sortable-offset-bug/&quot;&gt;jQuery Ui Sortable &#8211; Offset Bug&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/jquery-sortable-offset-bug/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zend Framework &#8211; GetText, Smarty and Automatically Adding The Translations</title>
		<link>http://blog.ricky-stevens.com/zend-framework-gettext-smarty-automatically-adding-translations/</link>
		<comments>http://blog.ricky-stevens.com/zend-framework-gettext-smarty-automatically-adding-translations/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 10:54:35 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Smarty]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Backend Development]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=301</guid>
		<description><![CDATA[Automatically add translations with Zend Framework, Smarty and GetText.]]></description>
			<content:encoded><![CDATA[<div>
<p><strong>Zend Translate</strong> is a great piece of kit, allowing you to switch between<strong> translation</strong> <strong>adapters</strong> with the flick of a few keys. <strong>GetText</strong> is my sin of choice, and that is what I&#8217;ll be talking about here. <strong>GetText</strong> itself can scan over projects and pick up all the <strong>translations</strong>, and drop them into your PO files. This is fantastic, as long as you stick to the extremely strict methods that <strong>GetText</strong> defines. But if I&#8217;m using <strong>Smarty</strong> translation blocks, how do I get <strong>GetText</strong> to pick them up? Because am I hell adding them all in by hand!</p>
<p><span id="more-301"></span></p>
<p><img title="More..." src="http://blog.ricky-stevens.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /></p>
<p>Well, the nasty answer is I couldn&#8217;t find a way to actually do it, without actually forking <strong>GetText</strong>. If anyone does know of a way, please feel free to post a comment with a better solution. First off lets check out the <strong>Smarty</strong>block code that I used throughout my View to pass the <strong>translation</strong> strings back.</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">&lt;?PHP</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <span class="kw2">function</span> smarty_block_t<span class="br0">&#40;</span><span class="re0">$params</span><span class="sy0">,</span> <span class="re0">$content</span><span class="sy0">,</span> <span class="re0">$smarty</span><span class="sy0">,</span> <span class="sy0">&amp;</span><span class="re0">$r</span><span class="sy0">,</span> <span class="re0">$t</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span> <span class="sy0">!</span> <a href="http://www.php.net/is_null"><span class="kw3">is_null</span></a><span class="br0">&#40;</span><span class="re0">$content</span><span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="re0">$translate</span> <span class="sy0">=</span> Zend_Registry<span class="sy0">::</span><span class="me2">get</span><span class="br0">&#40;</span> <span class="st_h">'Zend_Translate'</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <a href="http://www.php.net/stripslashes"><span class="kw3">stripslashes</span></a><span class="br0">&#40;</span><span class="re0">$translate</span><span class="sy0">-&gt;</span>_<span class="br0">&#40;</span><span class="re0">$content</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <span class="br0">&#125;</span></div></li>
</ol></div></div></div>
<p>This basically calls in <strong>Zend</strong> <strong>Registry</strong> (which was set up within the application bootstrap) and uses it to translate the passed string. Tthe code within my View would then look like the following;</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><div class="smarty" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="br0">&#123;</span>t<span class="br0">&#125;</span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.<span class="br0">&#123;</span><span class="sy0">/</span>t<span class="br0">&#125;</span></div></li>
</ol></div></div></div>
<p>Its not a new concept, its been used by <strong>Smarty</strong> enthusiasts for many a year. In my opinion it is a hell of a lot easier to read than the default <strong>Zend</strong>/<strong>GetText</strong> <strong>templating</strong>/<strong>translating </strong>mechanisms supplied by default.</p>
<p>So far this will<strong> translate</strong> any text given, as long as it is within the existing <strong>translation </strong>file. Great, but if the site has 50,000 {t} blocks, entering them in by hand is very impracticable.</p>
<p>My solution to this was to write my own adapter for <strong>Zend Translate</strong>, which extended <strong>GetText</strong>.</p>
<p>Please consider the code on the following .PHPS file.</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><div class="text" style="font-family:monospace;">http://dev.ricky-stevens.com/getText/getText.phps</div></div></div>
<p>As you can see, all this is really doing is high-jacking the translate method, and if the application is within the &#8216;development&#8217; it checks if the translation exists. If it doesn&#8217;t exist, it attempts to add it. The parent translate method is then called to carry out the <strong>translation</strong> with <strong>GetText</strong>.</p>
<p>For my example, your folder structure should resemble the following;</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><div class="text" style="font-family:monospace;"><ol><li class="li1"><div class="de1">/application</div></li>
<li class="li1"><div class="de1">/bin</div></li>
<li class="li1"><div class="de1">/languages</div></li>
<li class="li1"><div class="de1">&nbsp; /files</div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; /lang_de.mo</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; /lang_de.po</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; /lang_en.mo</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; /lang_en.po</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; /lang_fr.mo</div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; /lang_fr.po</div></li>
<li class="li1"><div class="de1">&nbsp; /translations</div></li>
<li class="li1"><div class="de1">/library</div></li>
<li class="li1"><div class="de1">/public</div></li>
</ol></div></div></div>
<p>The &#8216;translations&#8217; file is a text file which needs to be writeable by the application. The /files directory will also need to be writeable.</p>
<p>The last step is to load in the <strong>translation</strong> <strong>adapter</strong> inside the application Bootstrap. Please see the following method;</p>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1">protected <span class="kw2">function</span> _initLocale<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <a href="http://www.php.net/date_default_timezone_set"><span class="kw3">date_default_timezone_set</span></a><span class="br0">&#40;</span> <span class="st_h">'Europe/London'</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; Zend_Locale<span class="sy0">::</span><span class="me2">setDefault</span><span class="br0">&#40;</span> <span class="st_h">'en_GB'</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="re0">$objLocale</span> <span class="sy0">=</span> <span class="kw2">new</span> Zend_Locale<span class="br0">&#40;</span><span class="st_h">'en_GB'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; Zend_Registry<span class="sy0">::</span><span class="me2">set</span><span class="br0">&#40;</span> <span class="st_h">'Zend_Locale'</span> <span class="sy0">,</span> <span class="re0">$objLocale</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="re0">$translate</span> <span class="sy0">=</span> <span class="kw2">new</span> Zend_Translate<span class="br0">&#40;</span></div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; <span class="st_h">'My_Translate_Adapter_Gettext'</span><span class="sy0">,</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; APPLICATION_PATH <span class="sy0">.</span> <span class="st_h">'/../../languages/files/'</span><span class="sy0">,</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="st_h">'auto'</span><span class="sy0">,</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'disableNotices'</span> &nbsp; &nbsp;<span class="sy0">=&gt;</span> <span class="kw4">true</span><span class="sy0">,</span></div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'logUntranslated'</span> &nbsp; <span class="sy0">=&gt;</span> <span class="kw4">false</span><span class="sy0">,</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'scan'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sy0">=&gt;</span> Zend_Translate<span class="sy0">::</span><span class="me2">LOCALE_FILENAME</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">;</span> </div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp; Zend_Form<span class="sy0">::</span><span class="me2">setDefaultTranslator</span><span class="br0">&#40;</span><span class="re0">$translate</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; Zend_Validate_Abstract<span class="sy0">::</span><span class="me2">setDefaultTranslator</span><span class="br0">&#40;</span><span class="re0">$translate</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; Zend_Registry<span class="sy0">::</span><span class="me2">set</span><span class="br0">&#40;</span> <span class="st_h">'Zend_Translate'</span> <span class="sy0">,</span> <span class="re0">$translate</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$objLocale</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li>
</ol></div></div></div>
<p>This should now add in all<strong> translations</strong> from the View {t} blocks, <strong>Zend Form</strong> and <strong>Zend Validate</strong>. They will be added to all the <strong>GetText</strong> files within the /files directory. If anyone has any improvements or modifications on this, please feel free to leave a comment.</p>
<p>Hopefully this made somebody else&#8217;s life easier!</p>
</div>
<div class="su-linkbox" id="post-301-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/zend-framework-gettext-smarty-automatically-adding-translations/&quot;&gt;Zend Framework &#8211; GetText, Smarty and Automatically Adding The Translations&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/zend-framework-gettext-smarty-automatically-adding-translations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework &#8211; Get Route Name by URL</title>
		<link>http://blog.ricky-stevens.com/zend-framework-route-url/</link>
		<comments>http://blog.ricky-stevens.com/zend-framework-route-url/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 11:01:03 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Backend Development]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=298</guid>
		<description><![CDATA[Sounds easy enough really, or it should be anyway! When using a routes.ini with the Zend_Router, the concept is you only ever refer to the name of the route, rather than the URL itself. So if you have an awkward client that suddenly wants a URL changed on their website because their &#8220;SEO Expert&#8221; thought [...]]]></description>
			<content:encoded><![CDATA[<p>Sounds easy enough really, or it should be anyway! When using a routes.ini with the <strong>Zend_Router</strong>, the concept is you only ever refer to the name of the <strong>route</strong>, rather than the <strong>URL</strong> itself. So if you have an awkward client that suddenly wants a <strong>URL</strong> changed on their website because their &#8220;SEO Expert&#8221; thought it might be a good idea, you simply change the url against that <strong>Route name</strong>, and the whole website updates to use this <strong>URL</strong>. Better than spending several hours going through every page on the website and updating each link manually!</p>
<p><span id="more-298"></span></p>
<p>Recently I had a situation where I had a referer <strong>URL</strong>, and if the refer existed I wanted to be able to forward them to it. If it didn&#8217;t exist I needed to be able to forward them to a default <strong>route</strong>. This meant using the <strong>Zend</strong> <strong>Redirector</strong> Helpers method <span style="color: #993300;"><span style="text-decoration: underline;"><strong>gotoRoute()</strong></span></span>. Problem was one of these was a <strong>Route</strong>, and one of these was just a raw <strong>URL</strong>. So I needed to convert this raw <strong>URL</strong> to its corresponding <strong>route name</strong>. Took a bit of time in the <strong>Zend Framework</strong> API Docs, but eventually I found the method I needed.</p>
<p>As I needed the instance of the<strong> router</strong> inside a Controller Plugin, rather than a Controller itself, I had to create an instance of the Front Controller.</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1">Zend_Controller_Front<span class="sy0">::</span><span class="me2">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="sy0">-&gt;</span><span class="me1">getRouter</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="sy0">-&gt;</span><span class="me1">getCurrentRouteName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
</ol></div></div></div>
<p>This will return the <strong>Route Name</strong> of the page the script is called on.</p>
<div class="su-linkbox" id="post-298-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/zend-framework-route-url/&quot;&gt;Zend Framework &#8211; Get Route Name by URL&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/zend-framework-route-url/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Zend Framework &#8211; Working ACL Example</title>
		<link>http://blog.ricky-stevens.com/zend-framework-working-acl-example/</link>
		<comments>http://blog.ricky-stevens.com/zend-framework-working-acl-example/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 10:09:38 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Backend Development]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=291</guid>
		<description><![CDATA[I&#8217;ve recently had a couple of requests for an example project using Zend ACL, so I thought I&#8217;d set one up really quickly. I have to say that a lot of credit goes to Dave Clarke who implemented most of the code here at work for our current project. Hopefully this short description, and the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently had a couple of requests for an <strong>example</strong> project using <strong>Zend ACL</strong>, so I thought I&#8217;d set one up really quickly. I have to say that a lot of credit goes to <a href="http://blog.davidjclarke.co.uk/" target="_blank">Dave Clarke</a> who implemented most of the code here at work for our current project. Hopefully this short description, and the <strong>example</strong> install should help a few people out who are struggling with this largly undocumented <strong>ACL</strong>-shaped beast.</p>
<p><span id="more-291"></span></p>
<p>For this I created an example project using<strong> Zend Framework</strong> <strong>1.10</strong>. I then removed the <strong>Zend</strong> library, as I saw no point in making you download it just to see the <strong>example</strong> <strong>code</strong>. The database connectivity for the <strong>project</strong> I took this from was using Doctrine 1.2. The connectivity inside the library files still refers the Doctrine models, but I saw no need to include these as the arrays and datasets they pass back should be easy to re-create with your own models.</p>
<p>The files added to implement and activate the <strong>ACL</strong> are:</p>
<p><span style="color: #993300;"><span style="text-decoration: underline;">application/Bootstrap.php</span></span> &#8211; Added in an initiate method to load the <strong>ACL</strong> controller plugin.</p>
<p><span style="color: #993300;"><span style="text-decoration: underline;">library/My/Controller/Plugin/ACL.php</span></span> &#8211; The <strong>ACL</strong> controller plugin, checks and manages access levels</p>
<p><span style="color: #993300;"><span style="text-decoration: underline;">library/My/ACL/Exception.php</span></span> &#8211; Common <strong>ACL</strong> exception extending Zend_ACL_Exception</p>
<p><span style="color: #993300;"><span style="text-decoration: underline;">library/My/ACL/Factory.php</span></span> &#8211; Factory pattern for loading <strong>ACL</strong> properties</p>
<p><span style="color: #993300;"><span style="text-decoration: underline;">library/My/ACL/Resources.php</span></span> &#8211; Resource creation script</p>
<p>This is all untested, as I just grabbed it from a working project and dropped it into a fresh <strong>Zend Framework</strong> install to provide an example of an <strong>ACL</strong> setup. If there any problems or bugs with this implementation, just let me know and I&#8217;ll sort them out.</p>
<p>The archive file with the install can be downloaded <a href="http://dev.ricky-stevens.com/zf/zend-acl.rar" target="_blank">here</a>.</p>
<p>If you have any questions or queries, feel free to leave a comment.</p>
<div class="su-linkbox" id="post-291-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/zend-framework-working-acl-example/&quot;&gt;Zend Framework &#8211; Working ACL Example&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/zend-framework-working-acl-example/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Doctrine &#8211; Deep Copying of Relationships</title>
		<link>http://blog.ricky-stevens.com/doctrine-deep-copying-cloning-record-relationships/</link>
		<comments>http://blog.ricky-stevens.com/doctrine-deep-copying-cloning-record-relationships/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 15:11:05 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Backend Development]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=288</guid>
		<description><![CDATA[Doctrine is a fantastic ORM, and it is my preference when developing any large scale PHP application. However it has some holes in the documentation that catch me, and I assume many others, out every so often. One of these little hick-ups in the documentaiton came when a colleague and I were attempting to do [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Doctrine</strong> is a fantastic <strong>ORM</strong>, and it is my preference when developing any large scale <strong>PHP</strong> application. However it has some holes in the documentation that catch me, and I assume many others, out every so often. One of these little hick-ups in the documentaiton came when a colleague and I were attempting to do a <strong>deep copy</strong> or <strong>clone</strong> of a<strong> doctrine record</strong> with its loaded <strong>relationships</strong>. Simple according the <a href="http://www.doctrine-project.org/documentation/manual/1_0/hu/component-overview:record:getting-object-copy" target="_blank">documentation</a>.</p>
<p><span id="more-288"></span></p>
<p>The <span style="text-decoration: underline;"><span style="color: #993300;"><strong>copy()</strong></span></span>; method of the <strong>Doctrine Record</strong> only <strong>cloned</strong> itself, not any of its active <strong>relationships</strong>. See the following <strong>copy</strong> code:</p>
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="re0">$objRecord</span> <span class="sy0">=</span> Doctrine_Core<span class="sy0">::</span><span class="me2">getTable</span><span class="br0">&#40;</span><span class="st_h">'Table'</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">find</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="re0">$objRecord</span><span class="sy0">-&gt;</span><span class="me1">RelationshipOne</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2"><span class="re0">$objRecord</span><span class="sy0">-&gt;</span><span class="me1">RelationshipTwo</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="re0">$objRecord2</span> <span class="sy0">=</span> <span class="re0">$objRecord</span><span class="sy0">-&gt;</span><span class="me1">copy</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="re0">$objRecord2</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
</ol></div></div></div>
<p>This <strong>copy</strong> will only<strong> clone</strong> the initial <strong>Record</strong>, but ignores its <strong>relationships</strong>. According to the documentation, it will <strong>clone</strong> all<strong> records</strong> unless a <span style="color: #993300;"><span style="text-decoration: underline;">&#8216;false</span></span>&#8216; flag is passed. The documentation does not mention that by default, the flag is <span style="text-decoration: underline;"><span style="color: #993300;">&#8216;false&#8217;</span></span>, and will need to specifrically set to <span style="color: #993300;"><span style="text-decoration: underline;">&#8216;true&#8217;</span></span> for the <strong>relationships</strong> to be copied. See the following code:</p>
<div id="wpshdo_13" class="wp-synhighlighter-outer"><div id="wpshdt_13" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_13"></a><a id="wpshat_13" class="wp-synhighlighter-title" href="#codesyntax_13"  onClick="javascript:wpsh_toggleBlock(13)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_13" onClick="javascript:wpsh_code(13)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_print(13)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_13" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="re0">$objRecord</span> <span class="sy0">=</span> Doctrine_Core<span class="sy0">::</span><span class="me2">getTable</span><span class="br0">&#40;</span><span class="st_h">'Table'</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">find</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="re0">$objRecord</span><span class="sy0">-&gt;</span><span class="me1">RelationshipOne</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2"><span class="re0">$objRecord</span><span class="sy0">-&gt;</span><span class="me1">RelationshipTwo</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="re0">$objRecord2</span> <span class="sy0">=</span> <span class="re0">$objRecord</span><span class="sy0">-&gt;</span><span class="me1">copy</span><span class="br0">&#40;</span> <span class="kw4">true</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="re0">$objRecord2</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
</ol></div></div></div>
<p>This will now <strong>copy</strong>/<strong>clone</strong> the active <strong>relationships</strong> to the new<strong> record</strong> too.</p>
<div class="su-linkbox" id="post-288-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/doctrine-deep-copying-cloning-record-relationships/&quot;&gt;Doctrine &#8211; Deep Copying of Relationships&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/doctrine-deep-copying-cloning-record-relationships/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Overlaying Clickable Div Over Flash Movie</title>
		<link>http://blog.ricky-stevens.com/clickable-div-over-flash-movie/</link>
		<comments>http://blog.ricky-stevens.com/clickable-div-over-flash-movie/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 16:41:35 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Frontend Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=263</guid>
		<description><![CDATA[This plagued me for quite some time, and all I found by searching Google were answers that were either 100% wrong (and often idiotic), or people repeatedly saying &#8220;use wmode: transparent&#8220;. Yeah this is correct, but it didn&#8217;t fully accomplish the task at hand. After about 3 hours of searching and finding absolutely nothing of use, I [...]]]></description>
			<content:encoded><![CDATA[<p>This plagued me for quite some time, and all I found by searching Google were answers that were either 100% wrong (and often idiotic), or people repeatedly saying &#8220;<em>use <strong>wmode</strong>: <strong>transparent</strong></em>&#8220;. Yeah this is correct, but it didn&#8217;t fully accomplish the task at hand. After about 3 hours of searching and finding absolutely nothing of use, I started to do some proper R&amp;D to create my own solution to this problem.</p>
<p><span id="more-263"></span></p>
<p>The basic situation was I had a large array of<strong> Flash</strong> animations, which the client wanted to have <strong>animating</strong> from the page load. The user could then <strong>click</strong> on one of these <strong>flash movies</strong> to open up a <strong>JavaScript</strong> box with the appropriate content. In this project, I had no FLA&#8217;s. The client had outsourced the <strong>flash</strong> work to another company who would not release their source code, just the compiled <strong>SW</strong>F&#8217;s. My suspicion is they either ripped them off, or were embarrassed enough by the quality of the files they wouldn&#8217;t release them. But thats another story! The result was it left me with a large headache. With no way of using or hooking into the <strong>flash</strong> onClick event, my solution had to be purely <strong>HTML</strong>/<strong>CSS</strong>/<strong>JavaScript</strong>.</p>
<p>For my flash insertion I used <strong><a href="http://code.google.com/p/swfobject/" target="_blank">SWFObject</a></strong> which would replace a &#8220;no-flash&#8221; image with the appropriate markup to display the <strong>flash</strong> movie.</p>
<p>Firstly I followed the suggested methods and added {<strong>wmode</strong> : &#8220;<strong>transparent</strong>&#8221; } to my flash params. This caused a bit of a performance hit as it stopped the use of hardware acceleration, but a working prototype was better than no prototype at all! See the following code:</p>
<p><span style="color: #ff0000;"><strong><span style="text-decoration: underline;">Attempt 1</span></strong></span></p>
<div id="wpshdo_14" class="wp-synhighlighter-outer"><div id="wpshdt_14" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_14"></a><a id="wpshat_14" class="wp-synhighlighter-title" href="#codesyntax_14"  onClick="javascript:wpsh_toggleBlock(14)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_14" onClick="javascript:wpsh_code(14)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_14" onClick="javascript:wpsh_print(14)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_14" class="wp-synhighlighter-inner" style="display: block;"><div class="html4strict" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;js/jquery.min.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;js/swfobject.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span></div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; $(document).ready(function() {</div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; swfobject.embedSWF(&quot;flash/movie.swf&quot;, &quot;no-flash&quot;, &quot;195&quot;, &quot;120&quot;,</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &quot;9.0.0&quot;, &quot;flash/expressInstall.swf&quot;, {}, {wmode:&quot;transparent&quot;}, {});</div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; $('#div').live('click',function() {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; alert('click event');</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; });</div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp; });</div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span>&gt;</span></div></li>
<li class="li2"><div class="de2">&nbsp; #div {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; position:absolute;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; width: 195px;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; height: 120px;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; z-index: 5;</div></li>
<li class="li2"><div class="de2">&nbsp; }</div></li>
<li class="li1"><div class="de1">&nbsp; #div object, #div embed {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; position:absolute;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; width: 195px;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; height: 120px;</div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; z-index: 1;</div></li>
<li class="li1"><div class="de1">&nbsp; }</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;div&quot;</span>&gt;</span></div></li>
<li class="li2"><div class="de2">&nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;no-flash&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/no-flash.gif&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;</span></div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span></div></li>
</ol></div></div></div>
<p>This had the desired effect in <strong>Firefox</strong> and <strong>Opera</strong>, with the alert being triggered, but absolutely no luck with <strong>Safari</strong>/<strong>Chrome</strong> and <strong>Internet Explorer</strong>. The div with the event trigger on it was behind the flash movie. No good! The next approach was to create another <strong>div</strong>, and position it over the top of the first one. Logical, but I wasn&#8217;t really too hopeful. Consider the following code:</p>
<p><span style="color: #ff0000;"><span style="text-decoration: underline;"><strong>Attempt 2</strong></span></span></p>
<div id="wpshdo_15" class="wp-synhighlighter-outer"><div id="wpshdt_15" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_15"></a><a id="wpshat_15" class="wp-synhighlighter-title" href="#codesyntax_15"  onClick="javascript:wpsh_toggleBlock(15)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_15" onClick="javascript:wpsh_code(15)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_15" onClick="javascript:wpsh_print(15)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_15" class="wp-synhighlighter-inner" style="display: block;"><div class="html4strict" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;js/jquery.min.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;js/swfobject.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span></div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; $(document).ready(function() {</div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; swfobject.embedSWF(&quot;flash/movie.swf&quot;, &quot;no-flash&quot;, &quot;195&quot;, &quot;120&quot;,</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &quot;9.0.0&quot;, &quot;flash/expressInstall.swf&quot;, {}, {wmode:&quot;transparent&quot;}, {});</div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; $('#div').live('click',function() {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; alert('click event');</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; });</div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; $('#div2').live('click',function() {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; alert('click event on Div2');</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; });</div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; });</div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp; #div {</div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; position:absolute;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; width: 195px;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; height: 120px;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; z-index: 5;</div></li>
<li class="li1"><div class="de1">&nbsp; }</div></li>
<li class="li2"><div class="de2">&nbsp; #div object, #div embed {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; position:absolute;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; width: 195px;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; height: 120px;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; z-index: 1;</div></li>
<li class="li2"><div class="de2">&nbsp; }</div></li>
<li class="li1"><div class="de1">&nbsp; #div2 {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position:absolute;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 195px;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 120px;</div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z-index: 10;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 0;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: 0;</div></li>
<li class="li1"><div class="de1">&nbsp; }</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span></div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;div&quot;</span>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;no-flash&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/no-flash.gif&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;</span></div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2"><span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;div2&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span></div></li>
</ol></div></div></div>
<p>Oddly, this was slightly more successful. It worked perfectly in the <strong>Webkit</strong> browsers, but not so well in<strong> Internet Explorer</strong>. On <strong>Internet Explorer 8</strong>, the <strong>click</strong> event would be initiated if you clicked on a <strong>transparent</strong> part of the <strong>movie</strong>, but clicking on an opaque part of the <strong>movie</strong> didn&#8217;t fire the trigger. Predictably, <strong>IE7</strong> and <strong>IE6</strong> just ignored it.</p>
<p>This was about as far as Googling could take me as it was just the same useless answers over and over again. At this stage, I gave up on that and started looking for my own solution to the problem.</p>
<p>Logically thinking, <strong>Flash</strong> has its own loading point on the page which is after the rest of the DOM elements, so therefore should be above any other element. But after a bit of reading and  practical research, I discovered it wasn&#8217;t <strong>flash</strong> itself that had its own loading point, but the <strong>HTML</strong> <span style="color: #993300;"><span style="text-decoration: underline;">&lt;<strong>object</strong>&gt;</span></span> tag itself. This seemed like a step in the right direction, so I stuck with it. They key came when I discovered the various properties of the <span style="color: #993300;"><span style="text-decoration: underline;">&#8216;Type&#8217;</span></span> attribute of the tag. This allowed me to set the <strong>MIME</strong> type of the <strong>object</strong>, and use it for for other purposes than just <strong>Flash</strong>, allowing me to position another <strong>Object</strong> tag ontop of the <strong>Object</strong> tag housing the <strong>flash movie</strong>.</p>
<p>Consider the following code, which should solve this godforsaken headache forever.</p>
<p><strong><span style="text-decoration: underline;"><span style="color: #339966;">Attempt 3 &#8211; Solution</span></span></strong></p>
<div id="wpshdo_16" class="wp-synhighlighter-outer"><div id="wpshdt_16" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_16"></a><a id="wpshat_16" class="wp-synhighlighter-title" href="#codesyntax_16"  onClick="javascript:wpsh_toggleBlock(16)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_16" onClick="javascript:wpsh_code(16)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_16" onClick="javascript:wpsh_print(16)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_16" class="wp-synhighlighter-inner" style="display: block;"><div class="html4strict" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;js/jquery.min.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;js/swfobject.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span></div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; $(document).ready(function() {</div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; swfobject.embedSWF(&quot;flash/movie.swf&quot;, &quot;no-flash&quot;, &quot;195&quot;, &quot;120&quot;,</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &quot;9.0.0&quot;, &quot;flash/expressInstall.swf&quot;, {}, {wmode:&quot;transparent&quot;}, {});</div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; $('#div2').live('click',function() {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; alert('triggered a click');</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; });</div></li>
<li class="li1"><div class="de1">&nbsp; });</div></li>
<li class="li2"><div class="de2"><span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp; #div {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; position:relative;</div></li>
<li class="li2"><div class="de2">&nbsp; }</div></li>
<li class="li1"><div class="de1">&nbsp; #div2 {</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; position:absolute;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; z-index: 1;</div></li>
<li class="li1"><div class="de1">&nbsp; }</div></li>
<li class="li2"><div class="de2"><span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/style.html"><span class="kw2">style</span></a>&gt;</span> &nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;div&quot;</span>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;div2&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;width:195px;height:120px;&quot;</span>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/object.html"><span class="kw2">object</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;img/gif&quot;</span>&gt;</span></div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/null.gif&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;100%&quot;</span> <span class="kw3">height</span><span class="sy0">=</span><span class="st0">&quot;100%&quot;</span> <span class="sy0">/</span>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/object.html"><span class="kw2">object</span></a>&gt;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span> &nbsp;&nbsp; </div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;no-flash&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/no-flash.gif&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="sy0">/</span>&gt;</span> &nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp;<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span></div></li>
</ol></div></div></div>
<p>With this, you can see I&#8217;ve put the <span style="color: #993300;"><span style="text-decoration: underline;">#div2</span></span> <strong>div</strong> within the first <strong>div </strong>this time, but above the image that is being replaced by <strong>SWFObject</strong>. Inside this div is an <strong>Object </strong>tag with the <strong>MIME type</strong> set to <span style="text-decoration: underline;">&#8220;img/gif&#8221;</span>, and then obviously just an image within the <strong>object</strong> tag. This image is just a 1&#215;1 transparent gif. Therefore the <strong>Object</strong> with the image will be above the other due to DOM order and z-indexes.</p>
<p>This will now successfully trigger the alert on all the browsers I require.. <strong>FireFox</strong>, <strong>Safari</strong>, <strong>Chrome</strong>, <strong>Opera</strong>,<strong> Internet Explorer 8</strong>, <strong>Internet Explorer 7</strong> and <strong>Internet Explorer 6</strong>.</p>
<p>Hopefully this will make some peoples lives that little bit easier, and avoid the headache I went through with searching for answers.</p>
<p>If you have any questions or observations, please feel free to leave a comment.</p>
<div class="su-linkbox" id="post-263-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/clickable-div-over-flash-movie/&quot;&gt;Overlaying Clickable Div Over Flash Movie&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/clickable-div-over-flash-movie/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Rebuild Array Keys</title>
		<link>http://blog.ricky-stevens.com/php-rebuild-array-keys/</link>
		<comments>http://blog.ricky-stevens.com/php-rebuild-array-keys/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 10:13:44 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Backend Development]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=259</guid>
		<description><![CDATA[A common technique I use in PHP is to cycle an array and remove the array items which aren&#8217;t required for my operation. For instance if I&#8217;ve got an array of questions, and I need to remove all the questions that are already answered, as well as removing the questions that have been disabled or [...]]]></description>
			<content:encoded><![CDATA[<p>A common technique I use in <strong>PHP</strong> is to cycle an <strong>array</strong> and remove the <strong>array</strong> items which aren&#8217;t required for my operation. For instance if I&#8217;ve got an <strong>array</strong> of questions, and I need to remove all the questions that are already answered, as well as removing the questions that have been disabled or are irrelivent for that user, I will go through the question <strong>array</strong> and <span style="text-decoration: underline;"><span style="color: #993300;">unset()</span></span> the <strong>array item</strong>. This will leave me an <strong>array</strong> with only the required questions. Simple enough really, but a side effect of this is that all of the <strong>array keys</strong> are now foobar&#8217;d, so we will need to<strong> rebuild the array keys</strong>.</p>
<p><span id="more-259"></span></p>
<p>Consider the following code:</p>
<div id="wpshdo_17" class="wp-synhighlighter-outer"><div id="wpshdt_17" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_17"></a><a id="wpshat_17" class="wp-synhighlighter-title" href="#codesyntax_17"  onClick="javascript:wpsh_toggleBlock(17)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_17" onClick="javascript:wpsh_code(17)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_17" onClick="javascript:wpsh_print(17)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_17" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">&lt;?PHP</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <span class="re0">$arrPossible</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'a'</span><span class="sy0">,</span><span class="st_h">'b'</span><span class="sy0">,</span><span class="st_h">'c'</span><span class="sy0">,</span><span class="st_h">'d'</span><span class="sy0">,</span><span class="st_h">'e'</span><span class="sy0">,</span><span class="st_h">'f'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp; <span class="re0">$arrDisable</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'a'</span><span class="sy0">,</span><span class="st_h">'c'</span><span class="sy0">,</span><span class="st_h">'d'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span> <span class="re0">$arrPossible</span> <span class="kw1">as</span> <span class="re0">$key</span> <span class="sy0">=&gt;</span> <span class="re0">$val</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span> <a href="http://www.php.net/in_array"><span class="kw3">in_array</span></a><span class="br0">&#40;</span> <span class="re0">$val</span><span class="sy0">,</span> <span class="re0">$arrDisable</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unset"><span class="kw3">unset</span></a><span class="br0">&#40;</span> <span class="re0">$arrPossible</span><span class="br0">&#91;</span> <span class="re0">$key</span> <span class="br0">&#93;</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <a href="http://www.php.net/var_export"><span class="kw3">var_export</span></a><span class="br0">&#40;</span><span class="re0">$arrPossible</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp; <span class="coMULTI">/*</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; array(</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; &nbsp; 1 =&gt; 'b'</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; &nbsp; 4 =&gt; 'e'</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; &nbsp; 5 =&gt; 'f'</span></div></li>
<li class="li2"><div class="de2"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; )</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*/</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sy1">?&gt;</span></div></li>
</ol></div></div></div>
<p>As you can see, this technique leaves the original <strong>array keys</strong> in place, meaning they no longer associate the the offset of the <strong>array item</strong>. The way to <strong>rebuild</strong> this <strong>array</strong> and assign new <strong>offset keys</strong> is to use <strong>PHP</strong>&#8216;s <span style="text-decoration: underline;"><span style="color: #993300;">array_values()</span></span> function. See the following code:</p>
<div id="wpshdo_18" class="wp-synhighlighter-outer"><div id="wpshdt_18" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_18"></a><a id="wpshat_18" class="wp-synhighlighter-title" href="#codesyntax_18"  onClick="javascript:wpsh_toggleBlock(18)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_18" onClick="javascript:wpsh_code(18)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_18" onClick="javascript:wpsh_print(18)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ricky-stevens.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_18" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">&lt;?PHP</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <span class="re0">$arrPossible</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'a'</span><span class="sy0">,</span><span class="st_h">'b'</span><span class="sy0">,</span><span class="st_h">'c'</span><span class="sy0">,</span><span class="st_h">'d'</span><span class="sy0">,</span><span class="st_h">'e'</span><span class="sy0">,</span><span class="st_h">'f'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp; <span class="re0">$arrDisable</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'a'</span><span class="sy0">,</span><span class="st_h">'c'</span><span class="sy0">,</span><span class="st_h">'d'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span> <span class="re0">$arrPossible</span> <span class="kw1">as</span> <span class="re0">$key</span> <span class="sy0">=&gt;</span> <span class="re0">$val</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span> <a href="http://www.php.net/in_array"><span class="kw3">in_array</span></a><span class="br0">&#40;</span> <span class="re0">$val</span><span class="sy0">,</span> <span class="re0">$arrDisable</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unset"><span class="kw3">unset</span></a><span class="br0">&#40;</span> <span class="re0">$arrPossible</span><span class="br0">&#91;</span> <span class="re0">$key</span> <span class="br0">&#93;</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li2"><div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; <a href="http://www.php.net/var_export"><span class="kw3">var_export</span></a><span class="br0">&#40;</span> <a href="http://www.php.net/array_values"><span class="kw3">array_values</span></a><span class="br0">&#40;</span> <span class="re0">$arrPossible</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li2"><div class="de2">&nbsp; <span class="coMULTI">/*</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; array(</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; &nbsp; 0 =&gt; 'b'</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; &nbsp; 1 =&gt; 'e'</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; &nbsp; 2 =&gt; 'f'</span></div></li>
<li class="li2"><div class="de2"><span class="coMULTI">&nbsp; &nbsp;*&nbsp; )</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">&nbsp; &nbsp;*/</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="sy1">?&gt;</span></div></li>
</ol></div></div></div>
<p>Obviously this technique won&#8217;t apply to everyone, as many may wish to assign the unmatched <strong>array items</strong> to a new <strong>array</strong>. This works if there is only one routine to disable the <strong>array items</strong>, but when you&#8217;re working with a large number of routines to manipulate an <strong>array</strong>, I find it more efficient to modify the existing <strong>array</strong> and then <strong>rebuild</strong> its<strong> indexes</strong>, than keep creating new <strong>arrays</strong>.</p>
<div class="su-linkbox" id="post-259-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/php-rebuild-array-keys/&quot;&gt;PHP &#8211; Rebuild Array Keys&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/php-rebuild-array-keys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS &#8211; Element Naming Conventions</title>
		<link>http://blog.ricky-stevens.com/css-element-naming-conventions/</link>
		<comments>http://blog.ricky-stevens.com/css-element-naming-conventions/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:01:54 +0000</pubDate>
		<dc:creator>Ricky Stevens</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Frontend Development]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://blog.ricky-stevens.com/?p=248</guid>
		<description><![CDATA[Today I was passed an article entitled CSS: CamelCase Seriously Sucks! by Harry Roberts, by the front-end developer at work. You guessed it, the article was about CSS Naming Conventions. And it also doesn&#8217;t take a genius to work out that Harry Roberts isn&#8217;t a massive fan of CamelCase. A summary of his article is [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was passed an article entitled <span style="color: #993300;"><span style="color: #993300; text-decoration: underline;"><a href="http://csswizardry.com/2010/12/css-camel-case-seriously-sucks/" target="_blank">CSS: CamelCase Seriously Sucks</a>!</span><span style="color: #000000;"> by<a href="http://csswizardry.com/" target="_blank"> Harry Roberts</a>, by the front-end developer at work. You guessed it, the article was about <strong>CSS Naming Conventions</strong>. And it also doesn&#8217;t take a genius to work out that <strong>Harry Roberts</strong> isn&#8217;t a massive fan of <strong>CamelCase</strong>. A summary of his article is that as <strong>CSS</strong> uses a <strong>hyphenated delimiter</strong> for all its properties (eg background-color, z-index) you should name your <strong>CSS</strong> <strong>elements</strong> in the same <strong>hyphenated</strong> system. This is a valid point, and at first glance is very logical. However, if you take a step back it might not actually be that practical.</span></span></p>
<p><span style="color: #993300;"><span style="color: #000000;"><span id="more-248"></span></span></span></p>
<p><span style="color: #993300;"><span style="color: #000000;">I&#8217;ll disregard the parts of his article regarding scanning and readability as that is his opinion and not one for me to rebuke. I will also disregard the point of tabbing along a<strong> hyphenated</strong> string, as while this is a valid point, it all comes down to your development technique and what is easiest for you. Personally, its not easier for me, but that&#8217;s another debate entirely!</span></span></p>
<p><span style="color: #993300;"><span style="color: #000000;">My problem comes, when developers such as myself, develop across multiple languages on a day to day basis. In a typical day I might be doing <strong>HTML</strong>, <strong>CSS</strong>, <strong>JavaScript</strong>, <strong>PHP</strong>, <strong>SQL</strong> and <strong>Java</strong>. Of all of these languages, the ONLY language which supports <strong>hyphenated delimiters</strong> is <strong>CSS</strong>. This would be fine if these languages were stand-alone entities which didn&#8217;t cross over, but that isn&#8217;t the case.</span></span></p>
<p>For example, if I&#8217;m creating a<strong> HTML</strong> form, that will post to a <strong>PHP</strong> script, I have to take into account naming conventions. If I were to use<strong> HTML</strong>&#8216;s naming convention of single words with no delimiters, it would be fine in the markup itself, but all of my <strong>PHP</strong> superglobal variables would be single words. If I had a complex form where an element required more than one word for its name, I would need to disregard the HTML convention, and use a proper <strong>naming convention</strong>. If I was using CamelCase in my <strong>PHP</strong> code, it would therefore make sense to use <strong>CamelCase</strong> for my<strong> HTML </strong>form element names, as even though it isn&#8217;t quite accurate in the markup, it would be 100% consistent in the <strong>PHP</strong> code.</p>
<p>Another example, which directly relates to <strong>CSS</strong> and <strong>hyphen delimited</strong> <strong>naming conventions</strong> is the use of<strong> JavaScript</strong> within a web page. When using <strong>JavaScript</strong>, I&#8217;m constantly using <strong>CSS</strong> selectors from the DOM to attach events. <strong>JavaScript</strong> does not support <strong>hyphens</strong> in its variable names. This means that as I&#8217;m constantly refering to <strong>CSS selectors</strong>, creating new <strong>JavaScript variables</strong>, assigning new <strong>CSS</strong> classes and removing existing <strong>CSS</strong> classes, I would then have 2 different <strong>naming conventions</strong> embedded throughout the entire <strong>JavaScript</strong> file. I might then have <span style="color: #993300;"><span style="text-decoration: underline;">ANOTHER</span></span> set of <strong>naming conventions</strong> going on for my <strong>PHP</strong> code, which would be be used for <strong>AJAX</strong> calls. While none of this is going to end the world, if we&#8217;re talking about consistencies this is definitely worth being thrown into the debate.</p>
<p><strong>Camel Case</strong>, as well as <strong>underscore delimiters</strong>, are consistently usable through all of these languages, while<strong> hyphenated delimiters</strong> are not. When possible, I like to keep my <strong>conventions</strong> and techniques consistent through the entire project, as I believe this makes it easier for me to keep to grip with my code, and when someone takes a look at the project for the first time they will know that the <strong>convention</strong> they see on the first page will be the same on any other page within the system.</p>
<p>So while <strong>Harry Roberts</strong> has made a good point about the <strong>naming convention</strong> of <strong>CSS</strong>, I honestly believe it is an impractical naming convention for a system that consists of anything other than static <strong>CSS</strong> pages. If you want any kind of consistency through a big project, you need to take into account the abilities and <strong>conventions</strong> of all the languages in the system, not just jump at the first language you see and say &#8220;Yes, I&#8217;ll do it that way!&#8221;</p>
<div class="su-linkbox" id="post-248-linkbox"><div class="su-linkbox-label">Link to this post!</div><div class="su-linkbox-field"><input type="text" value="&lt;a href=&quot;http://blog.ricky-stevens.com/css-element-naming-conventions/&quot;&gt;CSS &#8211; Element Naming Conventions&lt;/a&gt;" onclick="javascript:this.select()" readonly="readonly" style="width: 100%;" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ricky-stevens.com/css-element-naming-conventions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

