<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: php code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 06 Oct 2008 10:24:22 GMT</pubDate>
    <description>DZone Snippets: php code</description>
    <item>
      <title>PHP: Sorting an associative array</title>
      <link>http://snippets.dzone.com/posts/show/3554</link>
      <description>This basically sorts an associative array... somethin' like that.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$people = new Array();&lt;br /&gt;&lt;br /&gt;$people[0]['id'] = 1;&lt;br /&gt;$people[0]['name'] = "Dave";&lt;br /&gt;$people[1]['id'] = 2;&lt;br /&gt;$people[1]['name'] = "Alex";&lt;br /&gt;$people[2]['id'] = 3;&lt;br /&gt;$people[2]['name'] = "Chris";&lt;br /&gt;&lt;br /&gt;function cmp($a, $b)&lt;br /&gt;{&lt;br /&gt;   return strcmp($a['name'], $b['name']);&lt;br /&gt;}&lt;br /&gt;usort($people, "cmp");&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 20 Feb 2007 15:02:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3554</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
    <item>
      <title>PHP variable check</title>
      <link>http://snippets.dzone.com/posts/show/3235</link>
      <description>ugh&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$page = isset($_GET['page']) ? $_GET['page'] : 'home';&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 03 Jan 2007 13:09:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3235</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
    <item>
      <title>PHP: Dynamically call a function from list of allowed actions</title>
      <link>http://snippets.dzone.com/posts/show/3234</link>
      <description>This function simply calls another function based on the argument, assuming that argument ($action) is in the "allowed" list of actions.&lt;br /&gt;&lt;br /&gt;settings-config.php&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$settings['actions'] = "list,view,delete,update";&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Catalog-class.php&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public function process_action($action) {&lt;br /&gt;	global $settings;&lt;br /&gt;	&lt;br /&gt;	$allowed_actions = explode(",",$settings['actions']);&lt;br /&gt;	if (is_numeric(array_search($action, $allowed_actions))) {&lt;br /&gt;		$f_name = "product_" . $action;&lt;br /&gt;		$this-&gt;$f_name();&lt;br /&gt;	} else {&lt;br /&gt;		$this-&gt;error_msg = 'ACTION_NOT_ALLOWED';&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;private function product_list() {&lt;br /&gt;}&lt;br /&gt;private function product_view() {&lt;br /&gt;}&lt;br /&gt;private function product_delete() {&lt;br /&gt;}&lt;br /&gt;private function product_update() {&lt;br /&gt;}&lt;br /&gt;private function product_create() {&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Even if product_create() exists, if you do process_action('create'), it will not work... it's basically like a function wrapper.. or something like that...&lt;br /&gt;&lt;br /&gt;UPDATE: Yes I know I could have created an array like &lt;code&gt;$settions['actions'] = array('list','view','delete','update');&lt;/code&gt; but I've modified this code a bit for snippet/display purposes... anyways this is just a reminder for myself, not of actual use or interest for others... comments are welcome though :D&lt;br /&gt;</description>
      <pubDate>Wed, 03 Jan 2007 12:15:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3234</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
    <item>
      <title>PHP: Connecting Flash to a Database (remoting)</title>
      <link>http://snippets.dzone.com/posts/show/3213</link>
      <description>There are many ways to do this.&lt;br /&gt;&lt;br /&gt;Depending on the backend language you're using, whether PHP, ColdFusion or other... you'll need to create some components (CFC's for ColdFusion), (Classes for PHP)... these are referred to as "services"&lt;br /&gt;&lt;br /&gt;Then you'll need to connect Flash to a remoting gateway (I use AMFPHP for PHP: www.amfphp.org).&lt;br /&gt;&lt;br /&gt;Either way, you'll need NetServices.as from Flash MX Remoting, call a gateway and retrieving a list of functions from your classes/components/services.&lt;br /&gt;&lt;br /&gt;Enough with the theory, here's how to do it with PHP:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/* /flashservices/services/Catalog.php */&lt;br /&gt;class Catalog {&lt;br /&gt;        var $products_array = array();&lt;br /&gt;&lt;br /&gt;// Constructor: Contains the list of methods available to the gateway&lt;br /&gt;function Catalog() {&lt;br /&gt;	$this-&gt;methodTable = array (&lt;br /&gt;		"getProducts" =&gt; array (&lt;br /&gt;			"description" =&gt; "Get list of products",&lt;br /&gt;			"access" =&gt; "remote",&lt;br /&gt;			"arguments" =&gt; "" // arguments could be optional, not tested&lt;br /&gt;		)&lt;br /&gt;	); // end methodTable&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function getProducts() {	&lt;br /&gt;	// your code goes here&lt;br /&gt;&lt;br /&gt;	return $this-&gt;products_array;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;!!!!!!!!! The code below is now deprecated !!!!!!!!&lt;br /&gt;---- see my other snippet to do this in Flash 8 ----&lt;br /&gt;&lt;br /&gt;Flash ActionScript (PHP Gateway):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "NetServices.as"&lt;br /&gt;NetServices.setDefaultGatewayUrl("http://yourserver.com/flashservices/gateway.php");&lt;br /&gt;gw = NetServices.createGatewayConnection();&lt;br /&gt;CatalogREMOTE = gw.getService("Catalog", this);&lt;br /&gt;CatalogREMOTE.getProducts();&lt;br /&gt;&lt;br /&gt;getProducts_Result = function(result) {&lt;br /&gt;	_root.products_results = result;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You parse the _root.products_results array however you want :D&lt;br /&gt;</description>
      <pubDate>Thu, 28 Dec 2006 00:34:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3213</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
    <item>
      <title>Load a PHP Class automatically upon instantiation (PHP5)</title>
      <link>http://snippets.dzone.com/posts/show/3179</link>
      <description>When you instantiate a class, it will try to load the file automatically.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function __autoload($class_name) {&lt;br /&gt;    require_once("classes/" . $class_name . ".php");&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;code&gt;$auth = new Auth;&lt;/code&gt;&lt;br /&gt;Will automatically load the file "classes/Auth.php"</description>
      <pubDate>Wed, 20 Dec 2006 00:23:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3179</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
  </channel>
</rss>
