<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Madarco DevBlog &#187; PHP</title>
	<atom:link href="http://blog.madarco.net/category/php/feed/" rel="self" type="application/rss+xml" />
	<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>
			<item>
		<title>How to make your own Zend Framework Resource Plugin</title>
		<link>http://blog.madarco.net/327/how-to-make-your-own-zend-framework-resource-plugin/</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>
]]></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>
		</item>
		<item>
		<title>MadaConsole &#8211; A debug console for Zend Framework</title>
		<link>http://blog.madarco.net/304/madaconsole-a-debug-console-for-zend-framework/</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>
]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/304/madaconsole-a-debug-console-for-zend-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Build a Facebook application with Zend Framework</title>
		<link>http://blog.madarco.net/91/build-a-facebook-application-with-zend-framework/</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>
]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/91/build-a-facebook-application-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>My two cents on Static Typing</title>
		<link>http://blog.madarco.net/72/my-two-cents-on-static-typing/</link>
		<comments>http://blog.madarco.net/72/my-two-cents-on-static-typing/#comments</comments>
		<pubDate>Wed, 16 May 2007 21:24:05 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/72/my-two-cents-on-static-typing/</guid>
		<description><![CDATA[While I was wondering if using haXe or Java with my server, I've stumbled upon some discussion on Static Typing (Java) vs. Dynamic Typing (Ruby, Php).
In a really interesting blog post (read the comments too) I found this touching phrase:
"Static typing is Communist Bureaucracy".
In short: since we (should) have pervasive testing, Static Typing is only [...]]]></description>
			<content:encoded><![CDATA[<p>While I was wondering if using haXe or Java with my server, I've stumbled upon some discussion on Static Typing (Java) vs. Dynamic Typing (Ruby, Php).<br />
In a <a href="http://memeagora.blogspot.com/2007/05/strong-typing-is-communist-bureaucracy.html">really interesting blog post (read the comments too)</a> I found this touching phrase:</p>
<blockquote><p>"Static typing is Communist Bureaucracy".</p></blockquote>
<p>In short: since we (should) have <em>pervasive testing</em>, Static Typing is only <em>more</em> testing. However, a comment is enlighting:</p>
<blockquote><p>I'm finding this logic hard to follow. Testing is good, coverage is good. Static typing is, among other things, a way to have the compiler test your code for type issues. Since we like testing, this makes static typing good, right?</p></blockquote>
<p>But Static Typing not only prevent you to do mistakes, like typos, it allows your IDE to know what you are doing:</p>
<blockquote><p><del>Dynamic</del> Static Typing speeds up development because there is physically less to type <strong>since ctrl+space and ctrl+2 write the declarations for you</strong>.</p></blockquote>
<p>Its seems obvious to me that Dynamic Typing is worth the catch only for a quick start or for learning.<br />
Since almost all of the dynamically typed languages (like Actionscript, Perl, Php) have migrated to some kind of Static Typing (eg: Type Inference), there should be a reason. </p>
<p>Periodically, a new Dynamically Typed language spawn, attracting junior/tired programmers with the mirage of the simplicity and the less-to-type-ing, riding the hype until his young audience grows and start doing large projects hoping not to call a function with the wrong arguments. </p>
<p>Only then they realize the big truth: Static Typing is just <strong>more informations in the source code</strong>.<br />
And more information means less <em>wondering-what-object-was</em> or <em>what-was-the-method-name-and-parameters</em> or <em>who-instantiate-this-object</em>, not to mention <a href="http://en.wikipedia.org/wiki/Static_code_analysis">static analysis</a>.</p>
<p>And hey, they have invented Javadoc-like documentation and <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html">Annotations</a> just to add some more information, why remove one of the most important?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/72/my-two-cents-on-static-typing/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>A better print_r: dBug</title>
		<link>http://blog.madarco.net/55/a-better-print_r-dbug/</link>
		<comments>http://blog.madarco.net/55/a-better-print_r-dbug/#comments</comments>
		<pubDate>Fri, 02 Mar 2007 17:38:27 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/55/a-better-print_r-dbug/</guid>
		<description><![CDATA[dBug is a php library that print a nice-formatted dump of a variable:
PHP:
PLAIN TEXT




include_once&#40;"dBug.php"&#41;;


&#160;


$variable = array&#40;


&#160; &#160; "first"=&#62;"1",


&#160; &#160; "second",


&#160; &#160; "third"=&#62;array&#40;


&#160; &#160; &#160; &#160; "inner third 1",


&#160; &#160; &#160; &#160; "inner third 2"=&#62;"yeah"&#41;,


&#160; &#160; "fourth"&#41;;


&#160;


new dBug&#40;$variable&#41;; 





Will be formatted like this:

Variable types supported are: Arrays, Objects, Recordsets and XML Resources.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://dbug.ospinto.com/">dBug</a> is a php library that print a nice-formatted dump of a variable:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-36"><a href="#" onclick="javascript:showPlainTxt('php-36'); return false;">PLAIN TEXT</a></span></div>
<div id="php-36">
<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;">include_once</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"dBug.php"</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: #0000ff;">$variable</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</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: #ff0000;">"first"</span>=&gt;<span style="color: #ff0000;">"1"</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: #ff0000;">"second"</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: #ff0000;">"third"</span>=&gt;array<span style="color: #66cc66;">&#40;</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: #ff0000;">"inner third 1"</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: #ff0000;">"inner third 2"</span>=&gt;<span style="color: #ff0000;">"yeah"</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: #ff0000;">"fourth"</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;">new</span> dBug<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$variable</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Will be formatted like this:<br />
<img src='http://blog.madarco.net/wp-content/uploads/dbug.JPG' alt='dBug' /></p>
<p>Variable types supported are: Arrays, Objects, Recordsets and XML Resources.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/55/a-better-print_r-dbug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple CakeAMFPhp How To</title>
		<link>http://blog.madarco.net/32/simple-cakeamfphp-how-to/</link>
		<comments>http://blog.madarco.net/32/simple-cakeamfphp-how-to/#comments</comments>
		<pubDate>Wed, 08 Nov 2006 09:47:00 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/32/simple-cakeamfphp-how-to/</guid>
		<description><![CDATA[It's been a while since I last wrote, sorry! I've been busy with work, thesis and some other suffs (which I'll be posting about in the next days).
One of those is AMFPhp: a method to connect Flash with Php.
Why AMF instead of JSON or XML? Basically because AMF is more mature than JSON, offer a [...]]]></description>
			<content:encoded><![CDATA[<p>It's been a while since I last wrote, sorry! I've been busy with work, thesis and some other suffs (which I'll be posting about in the next days).<br />
One of those is <a href="http://amfphp.sourceforge.net/">AMFPhp</a>: a method to connect Flash with Php.<br />
Why <a href="http://osflash.org/doku.php?id=amf">AMF</a> instead of JSON or XML? Basically because AMF is more mature than JSON, offer a ready-made and really complete set of classes, many utilities like the connection debugger component, a great Php implementation, and, above all, <a href="http://cakeforge.org/projects/cakeamfphp">CakeAMFPhp</a>. (<a href="http://osflash.org/doku.php?id=amf">AMF</a> is also a binary protocol on top of HTTP, so performance should be better than XML)<br />
<a href="http://cakeforge.org/projects/cakeamfphp">CakeAMFPhp </a>is the integration of AMFPhp and Cake, a Rails-inspired php framework. With Cake I've quickly build a prototype with the Bake command-line utility. Then I've started implementing the methods for the AMF calls. Thanks to the great database abstraction, every method is only few lines long.</p>
<p>Since CakeAMFPhp is a beta, I've found <a title="Cake model problem with AMF" href="http://osflash.org/pipermail/osflash_osflash.org/2006-October/011844.html">some problems</a>, for which I've found a quick fix that I'll explain shortly.</p>
<p>To start a CakeAMFPhp project, simply download the required libraries as explained in <a href="http://cakeamfphp.rd11.org/">this tutorial</a>. (<a href="http://manual.cakephp.org/appendix/blog_tutorial">If you are new to Cake you should also see this</a>)<br />
Then in your controller, for example GalleriesController, put this:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-43"><a href="#" onclick="javascript:showPlainTxt('php-43'); return false;">PLAIN TEXT</a></span></div>
<div id="php-43">
<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;">vendor<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"cakeamfphp/amf-core/util/MethodTable"</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;">vendor<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'cakeamfphp/amf-core/adapters/lib/Arrayft'</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;">vendor<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'cakeamfphp/amf-core/adapters/lib/Arrayf'</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> GalleriesController extends AppController</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;">...</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;">function</span> GalleriesController<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;"><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; <span style="color: #808080; font-style: italic;">//AMF:</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: #0000ff;">$this</span>-&gt;<span style="color: #006600;">methodTable</span> = MethodTable::<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">__FILE__</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; parent::__construct<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;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>In the line 11 we call the automatic method table constructor of AMFPhp: it read the javadoc-like comments in the file and do all the magic:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-44"><a href="#" onclick="javascript:showPlainTxt('php-44'); return false;">PLAIN TEXT</a></span></div>
<div id="php-44">
<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;">/**</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;">* @desc Return the list of public galleries</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;">* @access remote</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;">* @pagesize 25</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;">*/</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;">function</span> getGalleries<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$offset</span> = <span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #0000ff;">$limit</span> = <span style="color: #cc66cc;color:#800000;">25</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; <span style="color: #0000ff;">$data</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">Gallery</span>-&gt;<span style="color: #006600;">findAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #ff0000;">'created DESC'</span>, <span style="color: #0000ff;">$limit</span>, <span style="color: #0000ff;">$offset</span>, <span style="color: #cc66cc;color:#800000;">0</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: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;_arrayft<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span>, <span style="color: #ff0000;">'Gallery'</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>
<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;">function</span> getGalleries_count<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; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">Gallery</span>-&gt;<span style="color: #006600;">findCount</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;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The <code>@access remote</code> tag specify that the getGalleries method is callable from flash:</p>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div class="igBar"><span id="lactionscript-45"><a href="#" onclick="javascript:showPlainTxt('actionscript-45'); return false;">PLAIN TEXT</a></span></div>
<div id="actionscript-45">
<div class="actionscript">
<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;">var</span> ser = <span style="color: #000000; font-weight: bold;">new</span> Service<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"http://localhost/cake_gateway.php"</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #ff0000;">'GalleriesController'</span>, <span style="color: #000000; font-weight: bold;">null</span> , <span style="color: #000000; font-weight: bold;">null</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: #000000; font-weight: bold;">var</span> pc:PendingCall = ser.<span style="color: #006600;">getGalleries</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;">pc.<span style="color: #006600;">responder</span> = <span style="color: #000000; font-weight: bold;">new</span> RelayResponder<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">"handleResult"</span>, <span style="color: #ff0000;">"handleError"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>The <code>getGalleries_count()</code> method is needed for the pageable recordset:</p>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div class="igBar"><span id="lactionscript-46"><a href="#" onclick="javascript:showPlainTxt('actionscript-46'); return false;">PLAIN TEXT</a></span></div>
<div id="actionscript-46">
<div class="actionscript">
<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;">function</span> handleResult <span style="color: #66cc66;">&#40;</span>re:ResultEvent<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; <span style="color: #000000; font-weight: bold;">var</span> rs = RecordSet<span style="color: #66cc66;">&#40;</span>re.<span style="color: #006600;">result</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; rs.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'modelChanged'</span>, <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Listen for updateItems</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: #0066CC;">this</span>.<span style="color: #006600;">totalItems</span> = rs.<span style="color: #006600;">getLength</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">Number</span>=startFrom; i &lt;l; i++<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; item = rs.<span style="color: #006600;">getItemAt</span><span style="color: #66cc66;">&#40;</span>i<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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>i &lt;rs.<span style="color: #006600;">getNumberAvailable</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//It is already fetched</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;">//Process a row</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><code>getGalleries</code> return only the first 25 row from the database. When the data is loaded in flash, <code>rs.getLength()</code> method return the value from <code>getGalleries_count()</code>. <code>getItemAt</code> return an item or a future, we check if the item is loaded in the line 8. If the item isn't from the ones loaded, it is automatically  requested from the server when we call <code>getItemAt</code>. When it arrives, the <code>modelChanged</code> method is called:</p>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div class="igBar"><span id="lactionscript-47"><a href="#" onclick="javascript:showPlainTxt('actionscript-47'); return false;">PLAIN TEXT</a></span></div>
<div id="actionscript-47">
<div class="actionscript">
<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;">function</span> modelChanged <span style="color: #66cc66;">&#40;</span>info:<span style="color: #0066CC;">Object</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; <span style="color: #000000; font-weight: bold;">var</span> rs = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">rs</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: #000000; font-weight: bold;">var</span> item:<span style="color: #0066CC;">Object</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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>info.<span style="color: #006600;">eventName</span> == <span style="color: #ff0000;">"updateItems"</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; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">Number</span>=info.<span style="color: #006600;">firstItem</span>; i &lt;= info.<span style="color: #006600;">lastItem</span>; i++<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; item = rs.<span style="color: #006600;">getItemAt</span><span style="color: #66cc66;">&#40;</span>i<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; <span style="color: #0066CC;">target</span>.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>item<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;">&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 info object there are the rows received, you can configure Flash to get only the item required or the page containing it.<br />
That's all, simply add the <code>@access remote</code> tag, a <code>*methodname*_count</code> method and it works.<br />
You can find <a href="http://amfphp.sourceforge.net/docs/pageablerecordsets.html">more information on pageable recordsets here</a>.</p>
<p>The <code>_arrayft</code> is required for the issue I've talk about before: CakeAMFPhp 0.6 does not support sending recorset to flash, so this method is required to transform the data returned by the Cake database abstraction layer into a AMF-compatible recordset:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-48"><a href="#" onclick="javascript:showPlainTxt('php-48'); return false;">PLAIN TEXT</a></span></div>
<div id="php-48">
<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;">function</span> _arrayft<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span>, <span style="color: #0000ff;">$table</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; <span style="color: #0000ff;">$r</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>;</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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$table</span><span style="color: #66cc66;">&#93;</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; <span style="color: #808080; font-style: italic;">//Multi table query:</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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$table</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#93;</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; <span style="color: #808080; font-style: italic;">//Nested table:</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: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$table</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$t</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: #0000ff;">$r</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$t</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: #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;">&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; <span style="color: #808080; font-style: italic;">//Sigle record:</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: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$table</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$t</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: #0000ff;">$r</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$t</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: #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;">&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; <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; <span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$t</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; <a href="http://www.php.net/array_push"><span style="color: #000066;">array_push</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$r</span>, <span style="color: #0000ff;">$t</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$table</span><span style="color: #66cc66;">&#93;</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: #66cc66;">&#125;</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;">&nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Arrayf<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$r</span>, <a href="http://www.php.net/array_keys"><span style="color: #000066;">array_keys</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$r</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>&nbsp; <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: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>For performance reason, it is suggested to use a <a href="http://manual.cakephp.org/chapter/models">0 'recursive' value in the find(..) call</a>.<!-- ckey="0EE71214" --></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/32/simple-cakeamfphp-how-to/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some useful tips on Flash, caching and Php</title>
		<link>http://blog.madarco.net/27/some-usefull-tips-on-flash-caching-and-php/</link>
		<comments>http://blog.madarco.net/27/some-usefull-tips-on-flash-caching-and-php/#comments</comments>
		<pubDate>Tue, 12 Sep 2006 22:48:26 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/flash/some-usefull-tips-on-flash-caching-and-php/</guid>
		<description><![CDATA[Making the test for some strange flash cache behaviour I've learned some useful tips:
You can be sure a movie will be loaded appending a query string to the file name:
Actionscript:
PLAIN TEXT




loadMovie&#40;"clip.swf?123", target&#41;; 





&#160;
You can force the user to reload a movie when you release a new version:
Actionscript:
PLAIN TEXT




clipname= "cache"+VERSION+"-clip.swf";


loadMovie&#40;clipname, target&#41;; //Loaded


//After the first load the [...]]]></description>
			<content:encoded><![CDATA[<p>Making the test for <a href="http://blog.madarco.net/general/strange-flash-cache-behaviour-and-attachmovieanywhere-solution/">some strange flash cache behaviour</a> I've learned some useful tips:</p>
<h3>You can be sure a movie will be loaded appending a query string to the file name:</h3>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div class="igBar"><span id="lactionscript-54"><a href="#" onclick="javascript:showPlainTxt('actionscript-54'); return false;">PLAIN TEXT</a></span></div>
<div id="actionscript-54">
<div class="actionscript">
<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: #0066CC;">loadMovie</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"clip.swf?123"</span>, <span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>&nbsp;</p>
<h3>You can force the user to reload a movie when you release a new version:</h3>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div class="igBar"><span id="lactionscript-55"><a href="#" onclick="javascript:showPlainTxt('actionscript-55'); return false;">PLAIN TEXT</a></span></div>
<div id="actionscript-55">
<div class="actionscript">
<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;">clipname= <span style="color: #ff0000;">"cache"</span>+<span style="color: #0066CC;">VERSION</span>+<span style="color: #ff0000;">"-clip.swf"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">loadMovie</span><span style="color: #66cc66;">&#40;</span>clipname, <span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Loaded</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;">//After the first load the movie is cached:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">loadMovie</span><span style="color: #66cc66;">&#40;</span>clipname, target2<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Cached </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>And use a .htaccess file (ModRewrite required):</p>
<div class="syntax_hilite"><span class="langName">Apache:</span>
<div class="igBar"><span id="lapache-56"><a href="#" onclick="javascript:showPlainTxt('apache-56'); return false;">PLAIN TEXT</a></span></div>
<div id="apache-56">
<div class="apache">
<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: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">on</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #00007f;">RewriteCond</span> %<span style="color: #66cc66;">&#123;</span>REQUEST_URI<span style="color: #66cc66;">&#125;</span> cache<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;color:#800000;">0</span>-<span style="color: #ff0000;color:#800000;">9</span><span style="color: #66cc66;">&#93;</span>+<span style="color: #66cc66;">&#41;</span>-<span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>\.swf<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;"><span style="color: #00007f;">RewriteRule</span> ^cache<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;color:#800000;">0</span>-<span style="color: #ff0000;color:#800000;">9</span><span style="color: #66cc66;">&#93;</span>+<span style="color: #66cc66;">&#41;</span>-<span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>\.swf<span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>$ $<span style="color: #ff0000;color:#800000;">2</span>\.swf <span style="color: #66cc66;">&#91;</span>L<span style="color: #66cc66;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Only when you change the <code>VERSION</code> variable (<a href="http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_16417">pass it with flashVars</a>) the movie will be reload, <strong>otherwise it will be loaded from the browser cache</strong>.<br />
&nbsp;</p>
<h3>You can make cacheable a file downloaded through php:</h3>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-57"><a href="#" onclick="javascript:showPlainTxt('php-57'); return false;">PLAIN TEXT</a></span></div>
<div id="php-57">
<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;"><a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Last-Modified: '</span>.<a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">"D, j M Y G:i:s <span style="color: #000099; font-weight: bold;">\G</span><span style="color: #000099; font-weight: bold;">\M</span><span style="color: #000099; font-weight: bold;">\T</span>"</span>, <a href="http://www.php.net/filemtime"><span style="color: #000066;">filemtime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$filename</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Be sure to set the correct content type:</p>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div class="igBar"><span id="lphp-58"><a href="#" onclick="javascript:showPlainTxt('php-58'); return false;">PLAIN TEXT</a></span></div>
<div id="php-58">
<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;">$filename</span>= <span style="color: #ff0000;">"clip.swf"</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;">$fp</span> = @<a href="http://www.php.net/fopen"><span style="color: #000066;">fopen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$filename</span>,<span style="color: #ff0000;">"r"</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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$fp</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; <a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Last-Modified: '</span>.<a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">"D, j M Y G:i:s <span style="color: #000099; font-weight: bold;">\G</span><span style="color: #000099; font-weight: bold;">\M</span><span style="color: #000099; font-weight: bold;">\T</span>"</span>, <a href="http://www.php.net/filemtime"><span style="color: #000066;">filemtime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$filename</span><span style="color: #66cc66;">&#41;</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;">&nbsp; &nbsp; <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-Length: '</span>.<a href="http://www.php.net/filesize"><span style="color: #000066;">filesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$filename</span><span style="color: #66cc66;">&#41;</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; <a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Connection: close'</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; <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: application/x-shockwave-flash'</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;">&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/feof"><span style="color: #000066;">feof</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$fp</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; <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/fgets"><span style="color: #000066;">fgets</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$fp</span>, <span style="color: #cc66cc;color:#800000;">4096</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;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/ob_flush"><span style="color: #000066;">ob_flush</span></a><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;">&#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; <a href="http://www.php.net/fclose"><span style="color: #000066;">fclose</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$fp</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: #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: #b1b100;">else</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;">&#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; <a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"HTTP/1.0 404 Not Found"</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: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Without Last-Modified or ETag headers flash doesn't cache the files.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/27/some-usefull-tips-on-flash-caching-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
