<?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>philpalmieri &#187; flash</title>
	<atom:link href="http://philpalmieri.com/category/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://philpalmieri.com</link>
	<description>php, codeigniter, mysql, jquery, as3 &#38; flex</description>
	<lastBuildDate>Sat, 03 Apr 2010 04:51:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Codeigniter AMFPHP library &#8211; updated</title>
		<link>http://philpalmieri.com/2009/04/codeigniter-amfphp-library/</link>
		<comments>http://philpalmieri.com/2009/04/codeigniter-amfphp-library/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 00:47:30 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[amfphp]]></category>

		<guid isPermaLink="false">http://philpalmieri.com/?p=10</guid>
		<description><![CDATA[Update 11/24/09: In order to load other libraries/models into your models with AMFPHP, change the BASEPATH declaration in index.php to define&#40;'BASEPATH', realpath&#40;dirname&#40;__FILE__&#41;&#41;.'/'.$system_folder.'/'&#41;; This is more of a repost of my wiki page on Codeigniter&#8217;s site, but i needed filler content for my first few postings on my site. At first glance there is a lot [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Update 11/24/09</strong>: In order to load other libraries/models into your models with AMFPHP, change the BASEPATH declaration in index.php to</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #339933;">,</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$system_folder</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is more of a repost of my wiki page on Codeigniter&#8217;s site, but i needed filler content for my first few postings on my site.</p>
<p>At first glance there is a lot to digest, but it is actually a pretty simple installation and is basically just replacing the gateway file with a Codeigniter controller</p>
<h3>What it does</h3>
<p>This AMF library will give you full access to your Codeigniter Models, as well as any libraries. In other words, it was written to work with Codeigniter, as Codeigniter was intended to be used &#8211; and you can drop this into your existing setup.</p>
<h3>How??</h3>
<p>Instead of trying to bootstrap Codeigniter, or use models outside of your app.  We create a Codeigniter controller, and a Codeigniter AMFPHP library that uses AMFPHP as packaged. &#8211; Then you create an AMFPHP Services in the services folder that just extends your Codeigniter models, and gives you full access</p>
<h3>Full Working Example</h3>
<p>We have packaged up the entire working sample that includes a fresh Codeigniter 1.7.1, AMF 1.9 and 2 flash samples modified from the Open Source Flash Development book chapter by (<a href="http://www.wadearnold.com/blog">Wade Arnold</a>) and a sample product mysql table.</p>
<p>All of the sample code assumes you ARE NOT using a .htaccess file, and also assumes you are using the default everything.  If you have moved your app and system path outside your webroot (as you should) it should still work fine too.</p>
<p><a href="http://www.philpalmieri.com/public/clean-ci-amfphp.zip">Dowload the files</a></p>
<h3>And away we go: Instructions / Explanation of whats going on</h3>
<ul>
<li>Download Codeigniter and AMFPHP (or pull apart the link above)</li>
<li>Make sure Codeigniter works as expected before moving forward</li>
<li>Put the unzipped amfphp package into your libraries folder</li>
<li>Create your amf_gateway.php in &#8216;controllers&#8217;</li>
</ul>
<blockquote><p>This file replaces the need for gateway.php<br />
setup netConnection to &#8216;/index.php/amf_gateway&#8217;</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Amf_gateway <span style="color: #000000; font-weight: bold;">extends</span> Controller
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//Start our library (keep reading the tutorial)</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>load<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>library<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'amfci'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//Set new include path for services</span>
    <span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #339933;">,</span> <span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> AMFSERVICES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//startup the amf gateway service</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>amfci<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>service<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<ul>
<li>Create a standard Codeigniter model or use an existing one</li>
<li>Drop in the amfci_db.php file provided into &#8216;libraries/amfphp/services/amfci_db.php&#8217;</li>
<li>Create AMFPHP Service in &#8216;libraries/amfphp/services&#8217; folder using the template provided</li>
</ul>
<blockquote><p>This file is a service for AMFPHP &#8211; called from flash<br />
This extends your existing model to give flash access to all its methods</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Load CI DB Instance since we are not coming through index.php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'amfci_db.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Use this path if you are using a module (ie, MatchBox)</span>
<span style="color: #666666; font-style: italic;">// require_once(AMFSERVICES.'/../../../modules/test_shop/models/product_model.php');</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Use this path if you are using standard install</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>AMFSERVICES<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../../../models/your_model.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> your_model_service <span style="color: #000000; font-weight: bold;">extends</span> your_model
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">//Since extending your_model, all existing methods are available</span>
  <span style="color: #666666; font-style: italic;">//New Methods</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yourNewMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$something</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Create array to send to flash</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$something</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Add the amfci.php library to your library folder <em>The amfci library is used by amf_gateway controller that replaces the default gateway.php file, by creating an instance of the gateway as $this-&gt;gateway, and settign the needed options</em></p>
<blockquote><p>This file is the new amfphp library for CI<br />
It it loaded from the amf_gateway controller, and binds all of it together</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Amfci
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$gateway</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>CI <span style="color: #339933;">=</span> get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">require</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/amfphp/globals.php&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">require</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/amfphp/core/amf/app/Gateway.php&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AMFSERVICES'</span><span style="color: #339933;">,</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/amfphp/services&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>gateway <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Gateway<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>gateway<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setCharsetHandler<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;utf8_decode&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ISO-8859-1&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ISO-8859-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>gateway<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setLooseMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>gateway<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setErrorHandling<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">E_ALL</span> ^ <span style="color: #009900; font-weight: bold;">E_NOTICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>gateway<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setClassMappingsPath<span style="color: #009900;">&#40;</span>AMFSERVICES<span style="color: #339933;">.</span><span style="color: #0000ff;">'/vo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>gateway<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setClassPath<span style="color: #009900;">&#40;</span>AMFSERVICES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>PRODUCTION_SERVER<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//Disable profiling, remote tracing, and service browser</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>gateway<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>disableDebug<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> service<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>gateway<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>service<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Connect and call from flash</h3>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.page12.hello_world
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">MovieClip</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> fl.events.<span style="color: #000000; font-weight: bold;">*</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #000000; font-weight: bold;">*</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">NetConnection</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">Responder</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">ObjectEncoding</span>;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> gateway<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;/index.php/amf_gateway&quot;</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> connection<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">NetConnection</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> responder<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Responder</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      send_btn.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, sendData<span style="color: #000000;">&#41;</span>;
      responder = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Responder</span><span style="color: #000000;">&#40;</span>onResult, onFault<span style="color: #000000;">&#41;</span>;
      connection = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">NetConnection</span>;
      <span style="color: #009900;">//connection.objectEncoding = ObjectEncoding.AMF3;</span>
      connection.<span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span>gateway<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> sendData<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> params = server_txt.<span style="color: #004993;">text</span>;
      response_txt.<span style="color: #004993;">text</span> = <span style="color: #990000;">'Send '</span><span style="color: #000000; font-weight: bold;">+</span>server_txt.<span style="color: #004993;">text</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">' to server'</span>;
      connection.<span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;hello_world_service.say&quot;</span>, responder, params<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onResult<span style="color: #000000;">&#40;</span>result<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      response_txt.<span style="color: #004993;">text</span> = <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>result<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onFault<span style="color: #000000;">&#40;</span>fault<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      response_txt.<span style="color: #004993;">text</span> = <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>fault.<span style="color: #004993;">description</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://philpalmieri.com/2009/04/codeigniter-amfphp-library/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
