<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Madarco DevBlog</title>
	
	<link>http://blog.madarco.net</link>
	<description>on Flash, Java, Webdesign</description>
	<lastBuildDate>Mon, 03 Aug 2009 08:23:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/MadarcoDevblog" /><feedburner:info uri="madarcodevblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Adobe Wave</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/W6CLglW-qts/</link>
		<comments>http://blog.madarco.net/367/adobe-wave/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 07:50:49 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=367</guid>
		<description><![CDATA[Another cool product form Adobe: Adobe Wave
Adobe® Wave™ is an Adobe AIR® application and Adobe hosted service that work together to enable desktop notifications for web publishers, large and small.
Simply speaking it is an Air application that receive notifications from the Adobe free Publisher Service.
With Wave site owners can use a simple REST api to [...]]]></description>
			<content:encoded><![CDATA[<p>Another cool product form Adobe: <a href="http://labs.adobe.com/technologies/wave/developers/">Adobe Wave</a></p>
<blockquote><p>Adobe® Wave™ is an Adobe AIR® application and Adobe hosted service that work together to enable desktop notifications for web publishers, large and small.</p></blockquote>
<p>Simply speaking it is an Air application that receive notifications from the Adobe free <a href="https://ps-wave.adobe.com/portal/PublisherAdmin.html">Publisher Service</a>.<br />
With Wave site owners can use a simple REST api to send notifications, while desktop users can use a single application to receive notifications from multiple sources.</p>
<div id="attachment_370" class="wp-caption aligncenter" style="width: 260px"><a href="http://blog.madarco.net/wp-content/uploads/wave-flowchart.jpg"><img src="http://blog.madarco.net/wp-content/uploads/wave-flowchart.jpg" alt="Wave flowchart" title="wave-flowchart" width="250" height="298" class="size-full wp-image-370" /></a><p class="wp-caption-text">Wave flowchart</p></div>

<p><a href="http://feedads.g.doubleclick.net/~a/Cy7JzCumRcdGpNUZwAmz33MZxNA/0/da"><img src="http://feedads.g.doubleclick.net/~a/Cy7JzCumRcdGpNUZwAmz33MZxNA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Cy7JzCumRcdGpNUZwAmz33MZxNA/1/da"><img src="http://feedads.g.doubleclick.net/~a/Cy7JzCumRcdGpNUZwAmz33MZxNA/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/W6CLglW-qts" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/367/adobe-wave/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/367/adobe-wave/</feedburner:origLink></item>
		<item>
		<title>How to make your own Zend Framework Resource Plugin</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/HgL6r1pzjh4/</link>
		<comments>http://blog.madarco.net/327/how-to-make-your-own-zend-framework-resource-plugin/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 15:36:33 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=327</guid>
		<description><![CDATA[A recent release of Zend Framework intruduced Zend_Application: an organized way to bootstrap the framework without the need of an ugly boostrap.php file.
It comes with plugins support too, so let's see how to create one.
With Zend_Application you can not only setup all the components required (Zend_Table, Zend_View, Zend_Navigation, ecc) but you can also setup your [...]]]></description>
			<content:encoded><![CDATA[<p>A recent release of Zend Framework intruduced <a href="http://framework.zend.com/manual/en/zend.application.html">Zend_Application</a>: an organized way to bootstrap the framework without the need of an ugly boostrap.php file.<br />
It comes with plugins support too, so let's see how to create one.</p>
<p>With Zend_Application you can not only setup all the components required (Zend_Table, Zend_View, Zend_Navigation, ecc) but you can also setup your own custom plugin, called <strong>Resource</strong>.</p>
<p>In the Zend lingo a <strong>Resource</strong> is a plugin loaded by the Zend_Application and configured through the <em>application.ini</em> file or in the <em>Bootstrap.php</em> class.</p>
<p>A Resource can be used to setup a standard Zend component, routes, controller plugins or your custom component.</p>
<p>Lets see how.</p>
<h3>Use the Bootstrap class</h3>
<p>When you create an empty Zend Framework project with the <code>zf create project</code> command, you'll find a <em>Bootstrap.php</em> file in your <em>application</em> folder.</p>
<p>In this file there is a Bootstrap class that you can use to define your own resources by simply creating a method with the <code>_init</code> prefix. </p>
<p>For example:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showPlainTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Bootstrap extends Zend_Application_Bootstrap_Bootstrap</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> _initDoctype<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">bootstrap</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'view'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$view</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'view'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$view</span>-&gt;<span style="color: #006600;">doctype</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'XHTML1_STRICT'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>This setup a resource called <code>Doctype</code>.<br />
This resource simply set the doctype property in the view (which is a resource too).</p>
<p>With the <code>$this->bootstrap('view');</code> line, the <code>Doctype</code> resource requires the initialization of another resource: the <code>View</code>. In this way you can define dependencies in your resources.</p>
<p>You can even override the definition of a standard resource with your own, for example:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-9"><a href="#" onclick="javascript:showPlainTxt('php-9'); return false;">PLAIN TEXT</a></span></div>
<div id="php-9">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">protected <span style="color: #000000; font-weight: bold;">function</span> _initView<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">$view</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_View<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$view</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>In this way Zend_Application will use the <code>view</code> resource defined in your <code>_initView</code> method instead of the standard one.</p>
<p>With this method you can customize your Zend Framework with ease, but when you need to configure a standard component, like the db connection, there is a better approach: using the <em>application.ini</em>.</p>
<h3>Use the application.ini file</h3>
<p>Another gift of the <code>zf create project</code> command is the <code>application/configs/application.ini</code> file.</p>
<p>It contains all the configurations options of your application.<br />
You can for example use it to configure your db: </p>
<div class="syntax_hilite"><span class="langName">INI:</span>
<div class="igBar"><span id="lini-10"><a href="#" onclick="javascript:showPlainTxt('ini-10'); return false;">PLAIN TEXT</a></span></div>
<div id="ini-10">
<div class="ini">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resources.db.<span style="color: #000099;">adapter </span>= <span style="color: #933;">"pdo_mysql"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resources.db.params.<span style="color: #000099;">host </span>= <span style="color: #933;">"localhost"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resources.db.params.<span style="color: #000099;">username </span>= <span style="color: #933;">"root"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resources.db.params.<span style="color: #000099;">password </span>= <span style="color: #933;">""</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resources.db.params.<span style="color: #000099;">dbname </span>= <span style="color: #933;">"test"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resources.db.<span style="color: #000099;">isDefaultTableAdapter </span>=<span style="color: #660066;"> true </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>You could use either the Bootrap or the application.ini method for this task, however I personally prefer this method when configuring parameters that changes across the servers (development, testing, production) like the include paths or the db connection options.</p>
<h3>A better approach: Create a custom resource class</h3>
<p>To improve reusability, you can create a custom resource class, that can be easily distributed and configured through your application.ini.</p>
<p>Its simple: in your library create a <em>MyResource</em> folder and a <em>Custom</em> class:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-11"><a href="#" onclick="javascript:showPlainTxt('php-11'); return false;">PLAIN TEXT</a></span></div>
<div id="php-11">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//In library/MyResource/Custom.php:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> MyResource_Custom extends Zend_Application_Resource_ResourceAbstract </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getBootstrap</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">bootstrap</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'view'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$view</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getBootstrap</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">getResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'view'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$view</span>-&gt;<span style="color: #006600;">doctype</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'XHTML1_STRICT'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$view</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>In the <code>init</code> method, you can initialize your resource, and return it.<br />
The object returned will go in the resources repository, and it will be accessible with the <code>$bootstrap->getResource('custom')</code> call in the other resources. (hint: is case insensitive)</p>
<p>To use your newly created resource, you can simply put that in your application.ini:</p>
<div class="syntax_hilite"><span class="langName">INI:</span>
<div class="igBar"><span id="lini-12"><a href="#" onclick="javascript:showPlainTxt('ini-12'); return false;">PLAIN TEXT</a></span></div>
<div id="ini-12">
<div class="ini">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #666666; font-style: italic;">;Add the libray/MyResource folder to the plugin search path:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pluginPaths.<span style="color: #000099;">MyResource </span>= <span style="color: #933;">"MyResource"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #666666; font-style: italic;">;enable your Custom resource:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resources.<span style="color: #000099;">custom </span>=<span style="color: #660066;"> true </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>That's all.</p>
<p>A resource can take configuration options too, for example: </p>
<div class="syntax_hilite"><span class="langName">INI:</span>
<div class="igBar"><span id="lini-13"><a href="#" onclick="javascript:showPlainTxt('ini-13'); return false;">PLAIN TEXT</a></span></div>
<div id="ini-13">
<div class="ini">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #666666; font-style: italic;">;Add the libray/MyResource folder to the plugin search path:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pluginPaths.<span style="color: #000099;">MyResource </span>= <span style="color: #933;">"MyResource"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #666666; font-style: italic;">;enable your Custom resource while setting the &quot;doctype&quot; option:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resources.custom.<span style="color: #000099;">doctype </span>= <span style="color: #933;">"XHTML1_STRICT"</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Zend_Application will automatically initialize a resource when you set a configuration option in it.<br />
If our resource doesn't  expect a parameter, you can simply write <code>resources.*resourcename* = true</code>, like in the previous example.</p>
<p>You can access the options from within the resource through the <code>$this->options</code> variable. You can also define a setter method for the option:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-14"><a href="#" onclick="javascript:showPlainTxt('php-14'); return false;">PLAIN TEXT</a></span></div>
<div id="php-14">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//In library/MyResource/Custom.php:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> MyResource_Custom extends Zend_Application_Resource_ResourceAbstract </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$doctype</span> = <span style="color: #ff0000;">'XHTML1_STRICT'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//Setter method for the doctype option:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color: #000000; font-weight: bold;">function</span> setDoctype<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">doctype</span> = <span style="color: #0000ff;">$value</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getBootstrap</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">bootstrap</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'view'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$view</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getBootstrap</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">getResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'view'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$view</span>-&gt;<span style="color: #006600;">doctype</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">doctype</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$view</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>You are now ready to build your distributable plugin for Zend Framework, for other examples see the <em>Zend/Application/Resource</em> folder in the framework distribution or my <a href="http://blog.madarco.net/304/madaconsole-a-debug-console-for-zend-framework/">MadaConsole</a> resource.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/5R7hPSt4uZOkfUu6U4gGVbvoml4/0/da"><img src="http://feedads.g.doubleclick.net/~a/5R7hPSt4uZOkfUu6U4gGVbvoml4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/5R7hPSt4uZOkfUu6U4gGVbvoml4/1/da"><img src="http://feedads.g.doubleclick.net/~a/5R7hPSt4uZOkfUu6U4gGVbvoml4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/HgL6r1pzjh4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/327/how-to-make-your-own-zend-framework-resource-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/327/how-to-make-your-own-zend-framework-resource-plugin/</feedburner:origLink></item>
		<item>
		<title>MadaConsole – A debug console for Zend Framework</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/eEbZRQcZv-8/</link>
		<comments>http://blog.madarco.net/304/madaconsole-a-debug-console-for-zend-framework/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 10:32:22 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=304</guid>
		<description><![CDATA[Update: See my guide on How to make your own Zend Framework Resource Plugin
Building Facebook applications with Zend Framework, I've needed a debug console that can shows messages even in a Facebook canvas page, through an ajax request or a redirect.
For this purpose I've build a custom plugin for ZF that fits the need: it [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> See my guide on <a href="http://blog.madarco.net/327/how-to-make-your-own-zend-framework-resource-plugin/">How to make your own Zend Framework Resource Plugin</a></p>
<p>Building Facebook applications with Zend Framework, I've needed a debug console that can shows messages even in a Facebook canvas page, through an ajax request or a redirect.</p>
<p>For this purpose I've build a custom plugin for ZF that fits the need: it will sit under your pages and shows all your dumped object, messages and queries.<br />
<div id="attachment_311" class="wp-caption aligncenter" style="width: 367px"><a href="http://blog.madarco.net/wp-content/uploads/Madaconsoledetail2.jpg"><img src="http://blog.madarco.net/wp-content/uploads/Madaconsoledetail2.jpg" alt="MadaConsole debug console " title="MadaConsole Detail" width="357" height="158" class="size-full wp-image-311" /></a><p class="wp-caption-text">MadaConsole debug console </p></div></p>
<p>Usage is really simple: copy in your library and add the plugin in your Boostrap or application.ini.<br />
For a detailed guide see below.</p>
<h3>Features</h3>
<ul>
<li>Trace custom messages easily: <code>debug("A debug message");</code></li>
<li>Dump variables easily in your code with the pass-through function:<br />
Before: <code> array_count_values($arr);</code> After: <code>array_count_values(debug($arr));</code></li>
<li>Shows the queries executed by your Zend_Table</li>
<li>Shows debug messages even through redirects or ajax requests</li>
</ul>
<h3>Install</h3>
<p>Installing the plugin is simple:</p>
<ol>
<li>Download the archive: <a href='http://blog.madarco.net/wp-content/uploads/MadaConsole.zip'>MadaConsole</a></li>
<li>Unzip the library folder of the archive in the library folder of your Zend Framework application</li>
</ol>
<p>Then you can configure it with two methods: through your application.ini or in the Bootsrap class.</p>
<h4>Method1: application.ini</h4>
<p>Add those lines after <code>[development : production]</code>:<br />
<code><br />
pluginPaths.MadaConsole = "MadaConsole"<br />
resources.console = true<br />
</code></p>
<h4>Method 2: Bootstrap class</h4>
<p>Add this method:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-17"><a href="#" onclick="javascript:showPlainTxt('php-17'); return false;">PLAIN TEXT</a></span></div>
<div id="php-17">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #000000; font-weight: bold;">function</span> _initConsole<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> MadaConsole_Console::<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<h3>Usage</h3>
<p>Now in your code you can do:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-18"><a href="#" onclick="javascript:showPlainTxt('php-18'); return false;">PLAIN TEXT</a></span></div>
<div id="php-18">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">debug<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"A debug message"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">debug<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$myArray</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$data</span> = debug<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$myModel</span>-&gt;<span style="color: #006600;">findAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//It will recognize Zend_Db_* objects </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>With the pass-through functionality you can simply add the <code>debug()</code> function in your existing statements with ease: <code>$var = debug(my_func($foo));</code></p>
<p>To see the debug output when you do an ajax request, you can open a page of your choice in another browser window: the debug console will show all the messages site-wide.</p>
<h3>Downloads</h3>
<p><a href='http://blog.madarco.net/wp-content/uploads/MadaConsole.zip'>MadaConsole plugin</a><br />
<a href='http://blog.madarco.net/wp-content/uploads/MadaConsole-example-project.zip'>MadaConsole example Zend Framework project</a></p>
<div id="attachment_305" class="wp-caption aligncenter" style="width: 264px"><a href="http://blog.madarco.net/wp-content/uploads/madaconsole.jpg"><img src="http://blog.madarco.net/wp-content/uploads/madaconsole-254x300.jpg" alt="How the debug console looks like" title="MadaConsole - A Debug Console for Zend Framework" width="254" height="300" class="size-medium wp-image-305" /></a><p class="wp-caption-text">How the debug console looks like</p></div>

<p><a href="http://feedads.g.doubleclick.net/~a/EEtoXUpv9AJw1gQQNMxjgwvJTeg/0/da"><img src="http://feedads.g.doubleclick.net/~a/EEtoXUpv9AJw1gQQNMxjgwvJTeg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/EEtoXUpv9AJw1gQQNMxjgwvJTeg/1/da"><img src="http://feedads.g.doubleclick.net/~a/EEtoXUpv9AJw1gQQNMxjgwvJTeg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/eEbZRQcZv-8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/304/madaconsole-a-debug-console-for-zend-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/304/madaconsole-a-debug-console-for-zend-framework/</feedburner:origLink></item>
		<item>
		<title>Opera’s response to Google Weave: Opera Unite</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/jzVFPLqwcT0/</link>
		<comments>http://blog.madarco.net/301/operas-response-to-google-weave-opera-unite/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 10:44:28 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=301</guid>
		<description><![CDATA[Opera ha just announced Opera Unite: a web server that run inside the browser and that will offer functionalities similar to Google Weave.
Who will win the real-time web war?
]]></description>
			<content:encoded><![CDATA[<p>Opera ha just announced <a href="http://dev.opera.com/articles/view/an-introduction-to-opera-unite/">Opera Unite</a>: a web server that run inside the browser and that will offer functionalities similar to <a href="http://googleblog.blogspot.com/2009/05/went-walkabout-brought-back-google-wave.html">Google Weave</a>.</p>
<p>Who will win the real-time web war?</p>

<p><a href="http://feedads.g.doubleclick.net/~a/-SGgTdQiTY4u0bDYhnt83hak58M/0/da"><img src="http://feedads.g.doubleclick.net/~a/-SGgTdQiTY4u0bDYhnt83hak58M/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-SGgTdQiTY4u0bDYhnt83hak58M/1/da"><img src="http://feedads.g.doubleclick.net/~a/-SGgTdQiTY4u0bDYhnt83hak58M/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/jzVFPLqwcT0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/301/operas-response-to-google-weave-opera-unite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/301/operas-response-to-google-weave-opera-unite/</feedburner:origLink></item>
		<item>
		<title>Wonderfl – Collaboratively build flash demos</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/G5qSB1pSYB4/</link>
		<comments>http://blog.madarco.net/296/wonderfl-collaboratively-build-flash-demos/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 16:49:54 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=296</guid>
		<description><![CDATA[Simply Wonderfl, that site allows to write as3 code directly from the browser and compile the result, while other users are able to see it and fork it to create a new version. Like a flash demo scene on steroid.
Inestimable for finding nice effects for flash.
Some interesting examples:
Clouds rendering
"Dune" like desert generator
Retro avatars generator
Water ripple [...]]]></description>
			<content:encoded><![CDATA[<p>Simply <a href="http://wonderfl.kayac.com/">Wonderfl</a>, that site allows to write as3 code directly from the browser and compile the result, while other users are able to see it and fork it to create a new version. Like a flash demo scene on steroid.<br />
Inestimable for finding nice effects for flash.</p>
<p>Some interesting examples:<br />
<a href="http://wonderfl.kayac.com/code/2a89f8ce73761709029b59ade165662fb5f0e9d3">Clouds rendering</a><br />
<a href="http://wonderfl.kayac.com/code/9d2de22acc0df34bdd5eac0f861930b4393bd059">"Dune" like desert generator</a><br />
<a href="http://wonderfl.kayac.com/code/99db9f4dc72fd4f660750c1d5db06e7af8c4904a">Retro avatars generator</a><br />
<a href="http://wonderfl.kayac.com/code/235fa3e21768437bed8a3393f9bb1adb53d8921e">Water ripple effect</a></p>
<div id="attachment_297" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.madarco.net/wp-content/uploads/wonderfl.jpg"><img src="http://blog.madarco.net/wp-content/uploads/wonderfl-300x252.jpg" alt="Wonderfl - Build flash online" title="Wonderfl - Build flash online" width="300" height="252" class="size-medium wp-image-297" /></a><p class="wp-caption-text">Wonderfl - Build flash online</p></div>

<p><a href="http://feedads.g.doubleclick.net/~a/rnFtdk5nqg7xmIYGz89t4bzjaH0/0/da"><img src="http://feedads.g.doubleclick.net/~a/rnFtdk5nqg7xmIYGz89t4bzjaH0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/rnFtdk5nqg7xmIYGz89t4bzjaH0/1/da"><img src="http://feedads.g.doubleclick.net/~a/rnFtdk5nqg7xmIYGz89t4bzjaH0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/G5qSB1pSYB4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/296/wonderfl-collaboratively-build-flash-demos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/296/wonderfl-collaboratively-build-flash-demos/</feedburner:origLink></item>
		<item>
		<title>First Flash10 P2P application unveiled</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/nOOlLqAjyhY/</link>
		<comments>http://blog.madarco.net/288/first-flash10-p2p-application-unveiled/#comments</comments>
		<pubDate>Sun, 31 May 2009 11:34:39 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=288</guid>
		<description><![CDATA[Today I've found FilesOverMiles: a website that allows the exchange of files between two users with a P2P connection using Flash.
This is possible thanks to the new Flash 10 P2P capability.
However, this P2P feature needs an initial handshake between the clients to start the connection, and it is done through a "rendezvous service".
Since I didn't [...]]]></description>
			<content:encoded><![CDATA[<p>Today I've found <a href="http://www.filesovermiles.com/">FilesOverMiles</a>: a website that allows the exchange of files between two users with a P2P connection using Flash.<br />
This is possible thanks to the new Flash 10 P2P capability.</p>
<p>However, this P2P feature needs an initial handshake between the clients to start the connection, and it is done through a "rendezvous service".<br />
Since I didn't know that Adobe publicly released a rendezvous service or specification, have the folks at FilesOverMiles reverse engineered the protocol?</p>
<p>Useful links:<br />
<a href="http://labs.adobe.com/technologies/stratus/">Stratus: a rendezvous service from Adobe (beta)</a><br />
<a href="http://labs.adobe.com/technologies/afcs/">Flash Collaboration Serivice: Adobe hosting service for RTMP/RTMFP</a><br />
<a href="http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_rtmfp_faq_111208.pdf">Real-Time Media Flow Protocol FAQ</a><br />
<a href="http://blog.madarco.net/wp-content/uploads/rtmfp-big.gif"></p>
<div id="attachment_289" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.madarco.net/wp-content/uploads/rtmfp-big.gif"><img src="http://blog.madarco.net/wp-content/uploads/rtmfp-big-300x100.gif" alt="rtmfp" title="rtmfp" width="300" height="100" class="size-medium wp-image-289" /></a><p class="wp-caption-text">RTMFP</p></div>

<p><a href="http://feedads.g.doubleclick.net/~a/-9oBuxlITAKniZ1OKD8AxxzxL0k/0/da"><img src="http://feedads.g.doubleclick.net/~a/-9oBuxlITAKniZ1OKD8AxxzxL0k/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-9oBuxlITAKniZ1OKD8AxxzxL0k/1/da"><img src="http://feedads.g.doubleclick.net/~a/-9oBuxlITAKniZ1OKD8AxxzxL0k/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/nOOlLqAjyhY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/288/first-flash10-p2p-application-unveiled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/288/first-flash10-p2p-application-unveiled/</feedburner:origLink></item>
		<item>
		<title>RegExr – Write and share regular expressions</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/F1EibUmxB-U/</link>
		<comments>http://blog.madarco.net/281/regexr-write-and-share-regular-expressions/#comments</comments>
		<pubDate>Wed, 27 May 2009 08:55:08 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=281</guid>
		<description><![CDATA[Grant Skinner has just released RegExr: a wonderful tool for writing and sharing regular expressions.
Its main features are: show results as you type, contextual help, save and share your regexps.
It also runs as an Air application or directly from the website.
]]></description>
			<content:encoded><![CDATA[<p>Grant Skinner <a href="http://www.gskinner.com/blog/archives/2009/05/regexr_03b_rele.html">has just released</a> <a href="http://gskinner.com/RegExr/">RegExr</a>: a wonderful tool for writing and sharing regular expressions.</p>
<p>Its main features are: show results as you type, contextual help, save and share your regexps.<br />
It also runs as an Air application or directly from the <a href="http://gskinner.com/RegExr/">website</a>.</p>
<div id="attachment_282" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.madarco.net/wp-content/uploads/regexr.jpg"><img src="http://blog.madarco.net/wp-content/uploads/regexr-300x226.jpg" alt="RegExr" title="RegExr" width="300" height="226" class="size-medium wp-image-282" /></a><p class="wp-caption-text">RegExr</p></div>

<p><a href="http://feedads.g.doubleclick.net/~a/tG2XGkxELmxUcxqBaGXEe5jxlbM/0/da"><img src="http://feedads.g.doubleclick.net/~a/tG2XGkxELmxUcxqBaGXEe5jxlbM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tG2XGkxELmxUcxqBaGXEe5jxlbM/1/da"><img src="http://feedads.g.doubleclick.net/~a/tG2XGkxELmxUcxqBaGXEe5jxlbM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/F1EibUmxB-U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/281/regexr-write-and-share-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/281/regexr-write-and-share-regular-expressions/</feedburner:origLink></item>
		<item>
		<title>Using Zend_Tool in Eclipse</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/GYj47-X4k2s/</link>
		<comments>http://blog.madarco.net/263/using-zend_tool-in-eclipse/#comments</comments>
		<pubDate>Fri, 22 May 2009 20:29:30 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=263</guid>
		<description><![CDATA[Zend_Tool is a command line tool released with the latest version of Zend Framework. It will jump-start the development automating some tasks like the creation of an empty project or of a controller class.
Other than from the command line, its possible to use Zend_Tool directly from Eclipse, lets see how.
First, download the framework and extract [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://framework.zend.com/manual/en/zend.tool.project.html">Zend_Tool</a> is a command line tool released with the latest version of Zend Framework. It will jump-start the development automating some tasks like the creation of an empty project or of a controller class.</p>
<p>Other than from the command line, its possible to use Zend_Tool directly from Eclipse, lets see how.</p>
<div id="attachment_270" class="wp-caption aligncenter" style="width: 252px"><a href="http://blog.madarco.net/wp-content/uploads/zend_tool_in_eclipse.jpg"><img src="http://blog.madarco.net/wp-content/uploads/zend_tool_in_eclipse.jpg" alt="Use Zend_Tool from Eclipse" title="Use Zend_Tool from Eclipse" width="242" height="123" class="size-full wp-image-270" /></a><p class="wp-caption-text">Use Zend_Tool from Eclipse</p></div>
<p>First, <a href="http://www.zend.com/en/community/downloads">download the framework</a> and extract it.</p>
<p><em>I've had trouble with the full package of the 1.8.1 version, its seems to have a corrupted file in the tar.gz archive:<br />
<code>library\Zend\Tool\Framework\Loader\IncludePathLoader\RecursiveFilterIterator.php0000664</code><br />
you can resolve the problem simply by renaming it to <code>RecursiveFilterIterator.php</code></em></p>
<p>Now in Eclipse or Zend Studio for Eclipse, create and empty php project in a place accessible from your local webserver.</p>
<p>Now go to the "External tool" => "External Tools Configurations" panel to create a quick link to Zend_Tool.</p>
<p><em>NB: If you are using Zend Studio, you'll have to remove the filter that hide "Program" item first:</em><br />
<div id="attachment_265" class="wp-caption aligncenter" style="width: 523px"><a href="http://blog.madarco.net/wp-content/uploads/zend_studio_remove_filters.jpg"><img src="http://blog.madarco.net/wp-content/uploads/zend_studio_remove_filters.jpg" alt="In Zend Studio remove the filters that hide the Program item" title="How to remove the filters that hide the Program item" width="513" height="335" class="size-full wp-image-265" /></a><p class="wp-caption-text">In Zend Studio remove the filters that hide the Program item</p></div></p>
<p>Now you can create a new "external tool":</p>
<ol>
<li>Click the new item button</li>
<li>Give it a name</li>
<li>Point it to the location of the <code>bin\zf.bat</code> file in your zend framework folder (where you have extracted it) using the Browse File System button</li>
<li>Set the working directory to the location of your newly created php project with the Browse Workspace button</li>
<li>In the arguments box insert <code>${string_prompt}</code>. In this way Eclipse will prompt for input when you'll start the tool.</li>
</ol>
<div id="attachment_266" class="wp-caption aligncenter" style="width: 486px"><a href="http://blog.madarco.net/wp-content/uploads/create_external_tool.jpg"><img src="http://blog.madarco.net/wp-content/uploads/create_external_tool.jpg" alt="Create an External Tool in Eclipse" title="Create an External Tool in Eclipse" width="476" height="267" class="size-full wp-image-266" /></a><p class="wp-caption-text">Create an External Tool in Eclipse</p></div>
<p>Now in the "Enviroment" tab, configure two enviroment variable:</p>
<ul>
<li>Path: to your php.exe folder</li>
<li>ZEND_TOOL_INCLUDE_PATH_PREPEND: to your Zend Framework <code>library</code> folder</li>
</ul>
<p>In the Common tab check <code>Display in favorites menu</code> and in the "Refresh" tab check <code>Refresh resources upon completion => The project containing the selected resource</code></p>
<p>Now you can run it, and in the dialog write <code>show version</code>. In the Eclipse console you'll see the zend framework version.</p>
<p>Now you can experiment <a href="http://framework.zend.com/manual/en/zend.tool.project.providers.html">all the Zend_Tool commands</a> of your choice:</p>
<p><code>create project [absolute path of your project]</code><br />
<code>create controller [name of the controller]</code></p>
<p>And don't forget that you can <a href="http://framework.zend.com/manual/en/zend.tool.framework.html">create your own Zend_Tool command</a> too.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/h4kx1ww-BLD3VohaLIkp23iJ9u8/0/da"><img src="http://feedads.g.doubleclick.net/~a/h4kx1ww-BLD3VohaLIkp23iJ9u8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/h4kx1ww-BLD3VohaLIkp23iJ9u8/1/da"><img src="http://feedads.g.doubleclick.net/~a/h4kx1ww-BLD3VohaLIkp23iJ9u8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/GYj47-X4k2s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/263/using-zend_tool-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/263/using-zend_tool-in-eclipse/</feedburner:origLink></item>
		<item>
		<title>Haxe on the iPhone</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/CpU-XwPi1NM/</link>
		<comments>http://blog.madarco.net/251/haxe-on-the-iphone/#comments</comments>
		<pubDate>Fri, 22 May 2009 10:15:36 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=251</guid>
		<description><![CDATA[Great news for all the Haxe enthusiasts!
Haxe is powerful language similar to ActionScript 2, that can compile itself to Flash6/7/8/9/10 and translated to other languages like JavaScript, Php, NekoVM, C++.
This allows it to run virtually in every environment and client.
And now the good news: from today its possible to run Haxe programs on the iPhone! [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://gamehaxe.com/2009/05/22/haxe-on-iphone-simulator/">Great news</a> for all the <a href="http://haxe.org">Haxe</a> enthusiasts!</p>
<p>Haxe is powerful language similar to ActionScript 2, that can compile itself to Flash6/7/8/9/10 and <a href="http://haxe.org/doc/intro">translated</a> to other languages like JavaScript, Php, <a href="http://nekovm.org/">NekoVM</a>, C++.<br />
This allows it to run virtually in every environment and client.</p>
<p>And now the good news: from today its possible to <a href="http://gamehaxe.com/2009/05/22/haxe-on-iphone-simulator/">run Haxe programs on the iPhone</a>! </p>
<p>Beware that this is only an early beta, but it's already promising: thanks to the <a href="http://lib.haxe.org/p/nme">NME</a> library, you'll be able to use the Flash 9 drawing api on the iPhone, leveraging your Flash skills to make great iPhone games.</p>
<div id="attachment_258" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.madarco.net/wp-content/uploads/iphone1-300x235.png"><img src="http://blog.madarco.net/wp-content/uploads/iphone1-300x235.png" alt="Haxe on the iPhone simulator" title="Haxe on the iPhone simulator" width="300" height="235" class="size-full wp-image-258" /></a><p class="wp-caption-text">Haxe on the iPhone simulator</p></div>

<p><a href="http://feedads.g.doubleclick.net/~a/IbYEsBQPR3CPHgXHsznXtWLm2ow/0/da"><img src="http://feedads.g.doubleclick.net/~a/IbYEsBQPR3CPHgXHsznXtWLm2ow/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/IbYEsBQPR3CPHgXHsznXtWLm2ow/1/da"><img src="http://feedads.g.doubleclick.net/~a/IbYEsBQPR3CPHgXHsznXtWLm2ow/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/CpU-XwPi1NM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/251/haxe-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/251/haxe-on-the-iphone/</feedburner:origLink></item>
		<item>
		<title>Build a Facebook application with Zend Framework</title>
		<link>http://feedproxy.google.com/~r/MadarcoDevblog/~3/K8m7z7N3jVw/</link>
		<comments>http://blog.madarco.net/91/build-a-facebook-application-with-zend-framework/#comments</comments>
		<pubDate>Sun, 10 May 2009 15:56:38 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=91</guid>
		<description><![CDATA[I've just finished a Facebook game, so here a quick tutorial on how to use Zend Framework to build a Facebook Application.
Facebook basics
You can integrate your application with facebook in two way: with an IFRAME (using XFBML) or with FBML.
(If you are already familiar with how a Facebook application work you can skip this step)
Build [...]]]></description>
			<content:encoded><![CDATA[<p>I've just finished a <a href="http://apps.facebook.com/acrothegame/">Facebook game</a>, so here a quick tutorial on how to use Zend Framework to build a Facebook Application.</p>
<h3>Facebook basics</h3>
<p>You can integrate your application with facebook in two way: with an IFRAME (using <strong>X</strong>FBML) or with FBML.<br />
<em>(If you are already familiar with how a Facebook application work you can skip this step)</em></p>
<div id="attachment_226" class="wp-caption aligncenter" style="width: 414px"><img src="http://blog.madarco.net/wp-content/uploads/fbml-vs-iframe.gif" alt="You can embed your content in a Facebook page through FBML or use an IFRAME" title="FBML vs IFRAME" width="404" height="278" class="size-full wp-image-226" /><p class="wp-caption-text">You can embed your content in a Facebook page through FBML or use an IFRAME</p></div>
<h4>Build your website using FBML tags</h4>
<p>Facebook will be a proxy between your server and the user's browser: it will load a page form your own server like a normal browser, parse it, "enhance" it with his components and then embed it in a Facebook page. You will use standard HTML tags plus FBML tags.</p>
<p><strong>Pros:</strong></p>
<ul>
<li>You can use almost standard HTML, but with some other tags like: <code>&lt;fb:comments ... /></code>, <code>&lt;fb:wall ... /></code></li>
<li>Feature rich: with a simple tag integrate wall, comments, tabs, dashboard and many others components (<a href="http://wiki.developers.facebook.com/index.php/FBML">Complete list of facebook tags</a>)</li>
<li>The url in the browser follow the navigation</li>
<li>Faster when you need data from facebook database (groups, friends, etc.)</li>
</ul>
<p><strong>Cons:</strong></p>
<ul>
<li>Slower page load times: restart the facebook chat at every request</li>
<li>Can't use standard JavaScript, only <a href="http://wiki.developers.facebook.com/index.php/FBJS">FBJS</a> that's almost equals but your existing scripts and libraries won't work</li>
<li>Its losing ground: Facebook is trying to take IFRAME/XFBML on par</li>
</ul>
<h4>Embed using an IFRAME</h4>
<p>Use an iframe: just build a standard web site and let FB embeds it in an iframe</p>
<p><strong>Pros:</strong></p>
<ul>
<li>Better ajax support: you can use standard javascript, html and css</li>
<li>Easy to debug, its just a standard web site</li>
<li>Faster page load times</li>
</ul>
<p><strong>Cons:</strong></p>
<ul>
<li>Less features than with FBML (but XFBML is rapidly improving)</li>
<li>Slower when you need data from facebook database (eg: user's friends, groups, etc.)</li>
<li>The url in the browser doesn't follow the navigation</li>
<li>A bit more complex</li>
</ul>
<p>We'll start with FBML since its easier to use and to find help about on the forums.<br />
However take a look at XFBML in the future, since the Facebook team has really improved it recently and they are trying to push them on par.</p>
<p>See facebook wiki for further details on the <a href="http://wiki.developers.facebook.com/index.php/Choosing_between_an_FBML_or_IFrame_Application">differences between FMBL and IFRAME</a>.</p>
<h3>Integration</h3>
<p>First of all, <a href="http://developers.facebook.com/get_started.php">setup your FBML app</a> and write down your api key and secret key.</p>
<p>Just follow the onscreen instructions or the <a href="http://wiki.developers.facebook.com/index.php/Creating_your_first_application">wiki</a>, but care attention to the <strong>Canvas Page URL</strong>:<br />
it is something like: <code>http://apps.facebook.com/*APPLICATION_NAME*</code> and it is the url through the user can reach your app.</p>
<p>While the <strong>Canvas Callback URL</strong> (for example: <code>http://www.yourserver.com/fbapp</code>) its the address of your own web server, where you'll deploy your application.<br />
With a dynamic dns service like <a href="http://www.dyndns.com/">dyndns</a> you can create a domain name that map to the public address of your development machine, so that you can host your app on your dev machine while allowing Facebook to reach it.</p>
<p>Facebook will map every canvas url: <code>http://apps.facebook.com/*APPLICATION_NAME*/<strong>foo</strong></code> to your callback url: <code>http://www.yourserver.com/fbapp/<strong>foo</strong></code></p>
<p>After you have done with the setup, you can use the <a href="http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz">official PHP client</a> to interact with Facebook.</p>
<p>First, set up an empty Zend Framework project: you can use the Zend Studio for Eclipse wizard or the new <a href="http://akrabat.com/zend-framework-tutorial/">Zend_Tool command line</a>.</p>
<div id="attachment_195" class="wp-caption aligncenter" style="width: 486px"><img src="http://blog.madarco.net/wp-content/uploads/fb_zend_project.jpg" alt="Use Zend Studio wizard to create an empty Zend Framewrok project" title="Zend Framework skeleton" width="476" height="291" class="size-full wp-image-195" /><p class="wp-caption-text">Use Zend Studio wizard to create an empty Zend Framewrok project</p></div>
<p>Then, <a href="http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz">download the client</a> and copy the files in the <code>php</code> folder of the archive to the <code>library/facebook</code> folder of you Zend Framework project.</p>
<p>Now you can start using the client.</p>
<h3>The Controller</h3>
<p>To start, write in your <code>controllers/IndexController.php</code>:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-27"><a href="#" onclick="javascript:showPlainTxt('php-27'); return false;">PLAIN TEXT</a></span></div>
<div id="php-27">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Controller/Action.php'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$err</span> = <a href="http://www.php.net/error_reporting"><span style="color: #000066;">error_reporting</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">E_ERROR</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'facebook/facebook.php'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/error_reporting"><span style="color: #000066;">error_reporting</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$err</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> IndexController extends Zend_Controller_Action <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$apiKey</span> = <span style="color: #ff0000;">"22c...s05"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$apiSecret</span> = <span style="color: #ff0000;">"df6...fb5"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp;<span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$facebook</span> = <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">apiKey</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">apiSecret</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$facebook</span>-&gt;<span style="color: #006600;">require_login</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The line: <code>$err = error_reporting(E_ERROR);</code> is needed to hide some strange php notices from the facebook.php file.<br />
In the line 12 we instantiate our client with the api key and secret taken during the application set up.<br />
With the <code>require_login</code> method you can require the user to "add" your application.<br />
Notice that many api features are available only if the user has added the application.</p>
<p>Then in your Zend actions you can call every standard method of the <a href="http://wiki.developers.facebook.com/index.php/API">api</a> with the<br />
<code>$facebook->api_client </code> variable, for example:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-28"><a href="#" onclick="javascript:showPlainTxt('php-28'); return false;">PLAIN TEXT</a></span></div>
<div id="php-28">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$facebook</span>-&gt;<span style="color: #006600;">api_client</span>-&gt;<span style="color: #006600;">notifications_send</span><span style="color: #66cc66;">&#40;</span>...<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Send a notify to a user</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$facebook</span>-&gt;<span style="color: #006600;">api_client</span>-&gt;<span style="color: #006600;">friends_getAppUsers</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Get the friends of the current user that use your app</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//etc... </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>See <a href="http://wiki.developers.facebook.com/index.php/API">the complete list of methods</a> on the wiki and try them with the <a href="http://developers.facebook.com/tools.php?api">API console tool</a>.</p>
<h3>The View</h3>
<p>Now that you know how to interact with Facebook, you can show a simple page containing the <a href="http://wiki.developers.facebook.com/index.php/Fb:comments">"Comments box" component</a>.</p>
<p>In your <code>layouts/main.phtml</code> file write:</p>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div class="igBar"><span id="lhtml-29"><a href="#" onclick="javascript:showPlainTxt('html-29'); return false;">PLAIN TEXT</a></span></div>
<div id="html-29">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php echo $this-<span style="color: #000000; font-weight: bold;">&gt;</span></a></span>headScript() ?&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php echo $this-<span style="color: #000000; font-weight: bold;">&gt;</span></a></span>headStyle() ?&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php echo $this-<span style="color: #000000; font-weight: bold;">&gt;</span></a></span>layout()-&gt;nav ?&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;fb:title&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php echo $this-<span style="color: #000000; font-weight: bold;">&gt;</span></a></span>placeholder('title') ?&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>/fb:title&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php echo $this-<span style="color: #000000; font-weight: bold;">&gt;</span></a></span>layout()-&gt;content ?&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p>As you can see we don't have to put the standard html opening tags in your layout (<code>&lt;html>&lt;head>...</code>) since Facebook will load the page from your server and embed it in his own HTML canvas page.<br />
We had also used our first FBML tag: <code>&lt;fb:title></code> to set the page title in the browser titlebar (we can't use the ZF <code>headTitle()</code> method here).</p>
<p>Now create a view script for your index action of the index controller <code>views/scripts/index/index.phtml</code>:</p>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div class="igBar"><span id="lhtml-30"><a href="#" onclick="javascript:showPlainTxt('html-30'); return false;">PLAIN TEXT</a></span></div>
<div id="html-30">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php $this-<span style="color: #000000; font-weight: bold;">&gt;</span></a></span>placeholder('title')-&gt;set('My First Facebook App!'); ?&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Hello <span style="color: #009900;">&lt;fb:profile-pic uid=<span style="color: #ff0000;">'&lt;?php echo $this-&gt;</span>fbUserId ?&gt;' linked=&quot;true&quot;/&gt;!<span style="color: #009900;">&lt;br /&gt;</span> <span style="color: #009900;">&lt;br /&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Something to say?</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;fb:comments xid=&quot;myCommentsBox&quot; canpost=&quot;true&quot; candelete=&quot;false&quot; returnurl=&quot;http://apps.facebook.com/*APPLICATION_NAME*&quot;&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;">&lt;fb:title&gt;</span>My first comment Box<span style="color: #009900;">&lt;/fb:title&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;/fb:comments&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>This will place a comment box in your page. Notice that the <code>returnurl</code> property need to point to your <strong>canvas url</strong> and not your callback url. (substitute <code>*APPLICATION_NAME*</code> with your canvas url)</p>
<p>To experiment with the various <code>&lt;fb:* ></code> tags use the <a href="http://developers.facebook.com/tools.php?fbml">FBML console</a>.</p>
<p>Now you can go to your canvas url to see the result:</p>
<div id="attachment_234" class="wp-caption aligncenter" style="width: 310px"><img src="http://blog.madarco.net/wp-content/uploads/fist_app_facebook1-300x164.jpg" alt="Your first Facebook app with Zend Framework" title="Your first Facebook app with Zend Framework" width="300" height="164" class="size-medium wp-image-234" /><p class="wp-caption-text">Your first Facebook app with Zend Framework</p></div>
<p>In the HTML source of the canvas page you can see the original FBML used to generate the page and sometimes some errors/warnings.</p>
<h3>Javascript and CSS</h3>
<p>You can embed JavaScript in your FBML like in HTML, but only a special flavour of JavaScript: <a href="http://wiki.developers.facebook.com/index.php/FBJS">FBJS</a>.<br />
It is almost like the standard one, but there are some differences and your existing scripts and libraries won't work.</p>
<p>If you want to embed an external .js file, you'll have to specify the absolute path. Not only: Facebook will keep a copy of your script, even if you modify it, so you'll have to put a timestamp in the url to force a cache refresh.</p>
<p>For example, if you want to embed a script in your <code>index.phtml</code>:</p>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div class="igBar"><span id="lhtml-31"><a href="#" onclick="javascript:showPlainTxt('html-31'); return false;">PLAIN TEXT</a></span></div>
<div id="html-31">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php $this-<span style="color: #000000; font-weight: bold;">&gt;</span></a></span>headScript()-&gt;appendFile('http://www.yourserver.com/fbapp/scripts/js.js?v=' . filemtime('scripts/js.js')) ?&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p>In this way Facebook will load the script from the url: <code>http://www.yourserver.com/fbapp/scripts/js.js?v=1231707071</code>.<br />
When you'll edit the file, the number will change and FB will reload it.</p>
<p>The same apply to CSS:</p>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div class="igBar"><span id="lhtml-32"><a href="#" onclick="javascript:showPlainTxt('html-32'); return false;">PLAIN TEXT</a></span></div>
<div id="html-32">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>?php $this-<span style="color: #000000; font-weight: bold;">&gt;</span></a></span>headStyle()-&gt;appendFile('http://www.yourserver.com/fbapp/styles/fbstyle.css?v=' . filemtime('scripts/js.js')) ?&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p>CSS in FB is almost standard, but use absolute urls.<br />
Also be sure to write clean CSS, otherwise the Facebook parser will sometimes hang without and explanation.</p>
<h3>Make things easier</h3>
<p>We can use a base controller class.<br />
In <code>library/FacebookController.php</code> write:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-33"><a href="#" onclick="javascript:showPlainTxt('php-33'); return false;">PLAIN TEXT</a></span></div>
<div id="php-33">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$err</span> = <a href="http://www.php.net/error_reporting"><span style="color: #000066;">error_reporting</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">E_ERROR</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'facebook/facebook.php'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/error_reporting"><span style="color: #000066;">error_reporting</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$err</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> FacebookController extends Zend_Controller_Action <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$simulateFb</span> = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$useTestApplication</span> = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$apiKey</span> = <span style="color: #ff0000;">"28c...b05"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$apiSecret</span> = <span style="color: #ff0000;">"df6...fb5"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$canvasUrl</span> = <span style="color: #ff0000;">"http://apps.facebook.com/myfbapp"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$testApiKey</span> = <span style="color: #ff0000;">'28c...b05'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$testApiSecret</span> = <span style="color: #ff0000;">'df6...3fb5'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$testCanvasUrl</span> = <span style="color: #ff0000;">"http://apps.facebook.com/myfbapptest"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color: #0000ff;">$fbUserId</span> = <span style="color: #ff0000;">"1234567"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic;">/**</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp;* Facebook api</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp;* @var Facebook</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp;*/</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; protected <span style="color: #0000ff;">$facebook</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">simulateFb</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Zend_Session::<span style="color: #006600;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent::<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">useTestApplication</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">apiKey</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">testApiKey</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">apiSecret</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">testApiSecret</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">canvasUrl</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">testCanvasUrl</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">facebook</span> = <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">apiKey</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">apiSecret</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$session_key</span> = <a href="http://www.php.net/md5"><span style="color: #000066;">md5</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">facebook</span>-&gt;<span style="color: #006600;">api_client</span>-&gt;<span style="color: #006600;">session_key</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!Zend_Session::<span style="color: #006600;">isStarted</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>&nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Zend_Session::<span style="color: #006600;">setId</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$session_key</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Zend_Session::<span style="color: #006600;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent::<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> requireLogin<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">simulateFb</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">fbUserId</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">facebook</span>-&gt;<span style="color: #006600;">require_login</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> _redirect<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$url</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a> <span style="color: #0000ff;">$options</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">simulateFb</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">facebook</span>-&gt;<span style="color: #006600;">redirect</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">canvasUrl</span> . <span style="color: #0000ff;">$url</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;parent::_redirect<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$url</span>, <span style="color: #0000ff;">$options</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'Content-Type: text/html; charset=UTF-8'</span> <span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>In this way, our IndexController can be rewritten in this simplier way:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-34"><a href="#" onclick="javascript:showPlainTxt('php-34'); return false;">PLAIN TEXT</a></span></div>
<div id="php-34">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Controller/Action.php'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> IndexController extends FacebookController&nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp;<span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">requireLogin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">fbUserId</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">fbUserId</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>We had made <code>IndexController</code> inherit from <code>FacebookController</code>, and used its method <code>requireLogin</code>, without requiring to set up the Facebook client.</p>
<p>Not only:<br />
with the <code>$simulateFb</code> variable set to true you can preview your site outside the Facebook canvas page without requiring the login (but you'll not see the FBML components).</p>
<p>With <code>$useTestApplication</code> you can use a different pair of api key and secret for the development, while keeping your main application safe. (you need to set up another app to obtain the keys)</p>
<p>Also the FacebookController will allow the standard Zend Framework <code>_redirect</code> method to work and will bind Zend session to the one of Facebook.</p>
<p>Finally in the last line we set up the charset encoding to be sure it will be the same of the Facebook canvas page.</p>
<p>Thats all:<br />
now <a href="http://blog.madarco.net/wp-content/uploads/fb_zend_project.zip">download the tutorial sources</a> and start building your own Facebook app.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/tD7lm2iE4XczO8E6R8lPGLTgP9I/0/da"><img src="http://feedads.g.doubleclick.net/~a/tD7lm2iE4XczO8E6R8lPGLTgP9I/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tD7lm2iE4XczO8E6R8lPGLTgP9I/1/da"><img src="http://feedads.g.doubleclick.net/~a/tD7lm2iE4XczO8E6R8lPGLTgP9I/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/K8m7z7N3jVw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/91/build-a-facebook-application-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.madarco.net/91/build-a-facebook-application-with-zend-framework/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 4.011 seconds --><!-- Cached page served by WP-Cache -->
