<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Spabby&#039;s Blog</title>
	<atom:link href="http://spabby.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://spabby.wordpress.com</link>
	<description>An advernture into the Zend Framework and Facebook</description>
	<lastBuildDate>Fri, 11 Jun 2010 11:02:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='spabby.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Spabby&#039;s Blog</title>
		<link>http://spabby.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://spabby.wordpress.com/osd.xml" title="Spabby&#039;s Blog" />
	<atom:link rel='hub' href='http://spabby.wordpress.com/?pushpress=hub'/>
		<item>
		<title>FB.Connect.streamPublish – wrestling the demons of the Facebook JS library</title>
		<link>http://spabby.wordpress.com/2010/06/11/fb-connect-streampublish-%e2%80%93-wrestling-the-demons-of-the-facebook-js-library/</link>
		<comments>http://spabby.wordpress.com/2010/06/11/fb-connect-streampublish-%e2%80%93-wrestling-the-demons-of-the-facebook-js-library/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 11:02:57 +0000</pubDate>
		<dc:creator>spabby</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Publish to stream]]></category>
		<category><![CDATA[Stream Publish]]></category>
		<category><![CDATA[streamPublish]]></category>

		<guid isPermaLink="false">http://spabby.wordpress.com/?p=20</guid>
		<description><![CDATA[Yes, it’s true, I’ve officially mastered the most under documented API in history. We are currently using the FBML method of publishing our wonderful Lord of the Rings licensed game. All has been rosey in the garden of The One Ring, until we found out that the FBJS Flash bridge is the most unimpressive piece [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=20&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yes, it’s true, I’ve officially mastered the most under documented API in history.</p>
<p>We are currently using the FBML method of publishing our wonderful Lord of the Rings licensed game. All has been rosey in the garden of The One Ring, until we found out that the FBJS Flash bridge is the most unimpressive piece of script I have ever seen. We found that random errors would creep into the loading of the SWF because of this bridge, and decided that the only way around it was to bite the bullet and move to iframe mode.</p>
<p>For those who don’t know, iframe mode basically means you can side-step all the ridiculous limitations imposed upon you by Facebook, and basically just have your application sit in an iframe, interacting with Facebook through the API and a set of Javascript client libraries. The wonderful thing is that we could keep our “invite your friends!” and other fbml based pages as fbml. Hooray!</p>
<p>However, what I didn’t recon on was the amazing lack of documentation and examples when it comes to working in iframe mode. The crux of any successful Facebook app lies in self-publication, encouraging the user to tell the world how he has gained a new level in growing tulips, or played his longest Scrabble word ever. We wanted to be able to do this from within the PHP (well HTML if your being a pedant), or within the SWF. Simples. You’d think so, but apparently not.</p>
<p>After wrestling the Javascript library to the ground, I came to the following conclusions:</p>
<ol>
<li>The Facebook Javascript client library is woefully under-documented.</li>
<li>You need to use the FB.Connect functions, even though your application is not technically a Facebook Connect app.</li>
<li>You need to have an <a href="http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication_Channel">xd_receiver.htm</a> file on your server in order to communicate with the JS API.</li>
<li>You need to configure the callback URL on the “Connect” tab of the developer settings for your app.</li>
<li>You can then use the following code to spawn a stream post box…</li>
</ol>
<pre>&lt;CODE REMOVED, NOW OUT OF DATE! LEAVE A COMMENT IF NEW CODE WILL BE HANDY&gt;</pre>
<p>It’s a starting point at least, and as I’ve spend the last few days looking for just this example, I thought it might help someone down the line. This may not be the best way to achieve my goal, all comments would be received with thanks.</p>
<p>Also, you may well find FB.Connect.getStatus() handy, it was how I found out that my connect settings were wrong in the app settings page.</p>
<p>Useful Links:</p>
<ul>
<li>http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication_Channel</li>
<li>http://wiki.developers.facebook.com/index.php/JavaScript_Client_Library</li>
<li>http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.streamPublish</li>
<li>http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.get_status</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spabby.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spabby.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/spabby.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/spabby.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/spabby.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/spabby.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/spabby.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/spabby.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/spabby.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/spabby.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/spabby.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/spabby.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/spabby.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/spabby.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=20&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spabby.wordpress.com/2010/06/11/fb-connect-streampublish-%e2%80%93-wrestling-the-demons-of-the-facebook-js-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/476a730fa4ec27b84bde87db812eae00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spabby</media:title>
		</media:content>
	</item>
		<item>
		<title>Custom Messages for Zend_Form_Element::addValidator</title>
		<link>http://spabby.wordpress.com/2010/06/11/custom-messages-for-zend_form_elementaddvalidator/</link>
		<comments>http://spabby.wordpress.com/2010/06/11/custom-messages-for-zend_form_elementaddvalidator/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 10:59:03 +0000</pubDate>
		<dc:creator>spabby</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[addValidator]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<category><![CDATA[Zend_Form_Element]]></category>
		<category><![CDATA[Zend_Validate]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://spabby.wordpress.com/?p=18</guid>
		<description><![CDATA[Today I wanted to change the custom validation error messages that are generated when using Zend_Form. This isn’t as easy as I first hoped, because even with all of the documentation on the ZF site, I still had some problems understanding exactly what the Zend_Validate class needed to receive in order to display my custom [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=18&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I wanted to change the custom validation error messages that are generated when using Zend_Form. This isn’t as easy as I first hoped, because even with all of the documentation on the ZF site, I still had some problems understanding exactly what the Zend_Validate class needed to receive in order to display my custom errors.</p>
<p>Basically, each ::addValidtor method takes 3 parametres, the type of validator, wether to break the chain on validation failiure,  and an array of custom options.  One of these options (messages) needs to be set in order for the form to display your custom messages. These messages take the form of a key=&gt;value array where the key is they type of validation faliure (string of between 5 and 10 characters could be too short or too long), and the value is the custom error message.</p>
<p>For example:</p>
<pre>-&gt;addValidator('stringLength', true, array('min'=&gt;1, 'max'=&gt;32, 'messages'=&gt;array(Zend_Validate_StringLength::TOO_LONG =&gt;'The maximum number of characters is %max%')))</pre>
<p>This looks like a bit of a mess to me, so I decided to create an array of the messages arrays, and pass that to the options array instead.</p>
<p>One of the biggest changes to note, is that before I was using the custom messages, I was just passing the option parameters as values, and no in key=&gt;value pairs. For example in the stringLength example above, my old code was:</p>
<pre>-&gt;addValidator('stringLength', true, array(1,32))</pre>
<p>In fact, once I got my head around having to pass the custom options as key=&gt;value pairs, everything quickly fell into place.</p>
<p>As an extra aside, if you are using setRequired, and want to overwrite the default “Value is required and can’t be empty” message, simply add your own notEmpty validator with a custom error message as I’ve shown above.</p>
<p>For a list of constants each validator uses to put in your messages array see:</p>
<ul>
<li><a href="http://framework.zend.com/manual/en/zend.validate.messages.html">59.5. Validation Messages</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spabby.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spabby.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/spabby.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/spabby.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/spabby.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/spabby.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/spabby.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/spabby.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/spabby.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/spabby.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/spabby.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/spabby.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/spabby.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/spabby.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=18&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spabby.wordpress.com/2010/06/11/custom-messages-for-zend_form_elementaddvalidator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/476a730fa4ec27b84bde87db812eae00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spabby</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing a Custom View Helper</title>
		<link>http://spabby.wordpress.com/2010/06/11/writing-a-custom-view-helper/</link>
		<comments>http://spabby.wordpress.com/2010/06/11/writing-a-custom-view-helper/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 10:56:05 +0000</pubDate>
		<dc:creator>spabby</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[Custom View Helper]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Helper]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[View Helper]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://spabby.wordpress.com/?p=16</guid>
		<description><![CDATA[I wanted to write a set of functions available to me from the view to do some repetative tasks, such as converting a number to a set monetary format. It was obvious to me that I needed to write a custom view helper, but I had some small problems along the way that are worth [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=16&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wanted to write a set of functions available to me from the view to do some repetative tasks, such as converting a number to a set monetary format. It was obvious to me that I needed to write a custom view helper, but I had some small problems along the way that are worth mentioning.</p>
<p>The docs on the Zend Framework site on writing custom view helpers (<a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.custom">here</a>) are a little misleading. They say that as long as you follow the naming rules, that your helper will autoload and instanciate. The documentation give an example where the class is named My_View_Helper_SpecialPurpose. Having written my code, I found that the best way to get the class to autoload is to put the script in the views/helpers directory, and name it Zend_View_Helper_SpecialPurpose. Everything then worked with no changes needed to my bootstrap.</p>
<p>For those of you interested, here is my code:</p>
<p>/application/views/helpers/ToPounds.php</p>
<pre>class Zend_View_Helper_ToPounds extends Zend_View_Helper_Abstract
{
	/**
	* Returns an integer value converted to pounds
	*
	* @return string
	* @param $int Integer value to convert to £ format
	* @access public
	*/
	public function toPounds($int)
	{
		return htmlentities('£'.number_format($int, 2, '.', ','));
	}
}</pre>
<p>I can now call the function from within any view using:</p>
<pre>&lt;?php echo $this-&gt;toPounds(100); ?&gt;</pre>
<p>I hope that helps somebody.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spabby.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spabby.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/spabby.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/spabby.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/spabby.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/spabby.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/spabby.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/spabby.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/spabby.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/spabby.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/spabby.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/spabby.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/spabby.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/spabby.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=16&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spabby.wordpress.com/2010/06/11/writing-a-custom-view-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/476a730fa4ec27b84bde87db812eae00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spabby</media:title>
		</media:content>
	</item>
		<item>
		<title>AJAX interaction with PHP, using the ContextSwitch action helper</title>
		<link>http://spabby.wordpress.com/2010/06/11/ajax-interaction-with-php-using-the-contextswitch-action-helper/</link>
		<comments>http://spabby.wordpress.com/2010/06/11/ajax-interaction-with-php-using-the-contextswitch-action-helper/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 10:52:18 +0000</pubDate>
		<dc:creator>spabby</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://spabby.wordpress.com/?p=13</guid>
		<description><![CDATA[Well, when looking to simplify some actions and views that present JSON data to pass back from AJAX queries, I was pointed in the direction of the ContextSwitch action helper. One of the default contexts available, is the JSON context, which will disable all layout, and output serialized versions of any variables found in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=13&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well, when looking to simplify some actions and views that present JSON data to pass back from AJAX queries, I was pointed in the direction of the ContextSwitch action helper. One of the default contexts available, is the JSON context, which will disable all layout, and output serialized versions of any variables found in the view. This sounded perfect for what I wanted to achieve.</p>
<p>Basically, you tell the controller which additional contexts should be available in the init function of the controller, and then pass format=&lt;context&gt; to tell the action to render the page in that context. The code is:</p>
<pre>public function init()
{
	$contextSwitch = $this-&gt;_helper-&gt;getHelper('contextSwitch');
	$contextSwitch-&gt;addActionContext('saverss, 'json')
		      -&gt;initContext();
}</pre>
<p>You can then get anything set into a view variable json encoded by passing the querystring parameter format=json (or /format/json/), so:</p>
<pre>public function saverssAction()
{
	$this-&gt;view-&gt;response = array('x', 'y', 'z');
}</pre>
<p>Returns the JSON:</p>
<pre>{"controller":"mediaman","response":["x","y","z"]}</pre>
<p>This is really helpful when you have a number of actions that are called using AJAX from your front-end. Thanks to Bittarman in the #zftalk channel for the heads up.</p>
<p>More Reading…</p>
<ul>
<li><a href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html">Zend Framework Manual on Action Helpers</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spabby.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spabby.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/spabby.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/spabby.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/spabby.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/spabby.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/spabby.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/spabby.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/spabby.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/spabby.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/spabby.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/spabby.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/spabby.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/spabby.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=13&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spabby.wordpress.com/2010/06/11/ajax-interaction-with-php-using-the-contextswitch-action-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/476a730fa4ec27b84bde87db812eae00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spabby</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting view variables from within a FC Plugin</title>
		<link>http://spabby.wordpress.com/2010/06/11/setting-view-variables-from-within-a-fc-plugin/</link>
		<comments>http://spabby.wordpress.com/2010/06/11/setting-view-variables-from-within-a-fc-plugin/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 10:49:28 +0000</pubDate>
		<dc:creator>spabby</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Controller]]></category>
		<category><![CDATA[Every Controller]]></category>
		<category><![CDATA[FC Plugin]]></category>
		<category><![CDATA[Front]]></category>
		<category><![CDATA[Front Controller]]></category>
		<category><![CDATA[Front Controller Plugin]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[variable]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[View Variable]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://spabby.wordpress.com/?p=11</guid>
		<description><![CDATA[In my first post below, I covered how to create a FC plugin to ensure that a user is authenticated when they access every controller. As part of our layout, we want to include a generic style sheet in each page, and a custom style sheet for each controller to each rendered page. As in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=11&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my first post below, I covered how to create a FC plugin to ensure that a user is authenticated when they access every controller.</p>
<p>As part of our layout, we want to include a generic style sheet in each page, and a custom style sheet for each controller to each rendered page. As in the previous post, we wanted effectively to run some code in each and every controller, but did not want to have to include the code in each and every controller. As we already had a FC plugin that was handling the authentication, I decided to modify this to set a view variable that can be accessed from the layout.</p>
<p>Basically, this process takes 3 easy steps…</p>
<ol>
<li>Get an instance of the ViewRenderer</li>
<li>Initialise the view</li>
<li>Set the view variable</li>
</ol>
<p>This is pretty straight forward when you understand what you want to achieve, but took some getting right for me, thanks again to everyone in the #zftalk IRC channel for their patience on this one!</p>
<pre>// set a view variable with the controller name for access in the layout
// not strictly to do with authentication but it can sit here as a bonus
// create an instance of the view renderer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
// initilaise the view
$viewRenderer-&gt;initView();
// set a view variable to be the controller name
$viewRenderer-&gt;view-&gt;controller = $request-&gt;getControllerName();</pre>
<p>Basically that covers it, the trickiest part for me was learning to use the Zend_Controller_Action_HelperBroker to get the helper I needed to set the view variables. I hope this helps someone.</p>
<p>More reading…</p>
<ul>
<li><a href="http://framework.zend.com/manual/en/zend.controller.basics.html">Zend Framework manual entry on Zend_Controller</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spabby.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spabby.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/spabby.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/spabby.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/spabby.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/spabby.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/spabby.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/spabby.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/spabby.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/spabby.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/spabby.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/spabby.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/spabby.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/spabby.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=11&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spabby.wordpress.com/2010/06/11/setting-view-variables-from-within-a-fc-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/476a730fa4ec27b84bde87db812eae00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spabby</media:title>
		</media:content>
	</item>
		<item>
		<title>Want to do something in every single controller? Use a Front Controller Plugin</title>
		<link>http://spabby.wordpress.com/2010/06/11/want-to-do-something-in-every-single-controller-use-a-front-controller-plugin/</link>
		<comments>http://spabby.wordpress.com/2010/06/11/want-to-do-something-in-every-single-controller-use-a-front-controller-plugin/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 10:41:31 +0000</pubDate>
		<dc:creator>spabby</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Controller]]></category>
		<category><![CDATA[Every Controller]]></category>
		<category><![CDATA[FC Plugin]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Front]]></category>
		<category><![CDATA[Front Controller]]></category>
		<category><![CDATA[Front Controller Plugin]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://spabby.wordpress.com/?p=5</guid>
		<description><![CDATA[On our latest site, we are splitting the actual website into 3 different applications. Although some will be screaming “use Zend’s module feature!”, there is a good reason why we want to do this. Mainly, it’s because, the actually front-end advertising website will be hosted on a different domain to the actual content-rich back-end. Part [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=5&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On our latest site, we are splitting the actual website into 3 different applications. Although some will be screaming “use Zend’s module feature!”, there is a good reason why we want to do this. Mainly, it’s because, the actually front-end advertising website will be hosted on a different domain to the actual content-rich back-end.</p>
<p>Part of this logic means that for the site we are currently developing, every single controller used in the back-end needs to check if the user is authenticated, and if not, needs to forward the user to the login controller.  The easy way to do this is to use call the Auth model in each controllers _init function, and do the check there. What I wanted to achieve was a global site-wide check on each and every controller so that all the authentication checks are in one place.</p>
<p>Step forward the Front Controller plugin.</p>
<p>Firstly, you have to understand a little about how the dispatch process works in order to fully understand how and where to create your FC plugin. I found reading the Zend_Controller Basics page of the Zend Framework manual extremely helpful (see “More reading…” below).</p>
<p>The next question was where do I want the authentication to take place.  I decided that before the dispatch process was best, and so decided to bind my function at the pre-dispatch stage.  It saves the whole dispatch process from being run-through if the user is not authenticated.</p>
<p>So, to the code; firstly, I created the plugin that extends Zend_Controller_Plugin_Abstract.</p>
<pre>application/plugins/AuthPlugin.php
/**
 * Application auth plugin
 *
 * @uses Zend_Controller_Plugin_Abstract
 */

class Central_Plugin_AuthPlugin extends Zend_Controller_Plugin_Abstract
{
	 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
	 {
	 	// if not logged in, redirect to the login page
	 	// create an instance of Zend_Auth
	 	$auth = Zend_Auth::getInstance();
	 	// if not logged in
		if (!$auth-&gt;hasIdentity())
		{
			// set the new controller name to be the login controller
			$request-&gt;setControllerName('login')
			// set dispached to be false so the dispatch loop starts again
			-&gt;setDispatched(false);
		}
	 }
}</pre>
<p>Next up, we need to load the plugin from the bootstrap:</p>
<pre>// grab an instance of the front controller
$front = Zend_Controller_Front::getInstance();
// register a fc plugin
$front-&gt;registerPlugin(new Central_Plugin_AuthPlugin());
// go go go!
$front-&gt;dispatch();</pre>
<p>It’s really as simple as that, I would like to investigate in the future loading the controller from the application.ini which I believe is possible. But for now, this works.</p>
<p>Edit:<br />
Using the application.ini really is a much simpler way of loading your plugins… try this on for size:</p>
<pre>resources.frontController.plugins[] = "Plugin_AuthPlugin"</pre>
<p>More reading…</p>
<ul>
<li><a href="http://framework.zend.com/manual/en/zend.controller.basics.html">Zend Framework manual entry on Zend_Controller</a></li>
<li><a href="http://devzone.zend.com/article/3372-Front-Controller-Plugins-in-Zend-Framework">Zend Framework Devzone Article on Front Controller Plugins</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spabby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spabby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/spabby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/spabby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/spabby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/spabby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/spabby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/spabby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/spabby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/spabby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/spabby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/spabby.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/spabby.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/spabby.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spabby.wordpress.com&amp;blog=14152133&amp;post=5&amp;subd=spabby&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spabby.wordpress.com/2010/06/11/want-to-do-something-in-every-single-controller-use-a-front-controller-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/476a730fa4ec27b84bde87db812eae00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spabby</media:title>
		</media:content>
	</item>
	</channel>
</rss>
