My favorites | Sign in
Project Logo
                
Search
for
Updated Jan 18, 2009 by ben.lago...@gozer.com.au
Extras_swxCI  
The swxCI library, a CodeIgniter enabled SWX gateway

The swxCI library, a CodeIgniter enabled SWX gateway

swxCI is a short name for swx CodeIgniter.

swxCI allows you to use CodeIgniter controllers are service classes. This gives you access to the vast collection of libraries included in CodeIgniter, including the Database, ActiveRecord, Session, etc libraries.

Note: If you are not familiar with CodeIgniter, please check out the CodeIgniter documentation. This document assumes a minimum knowledge of CodeIgniter.

Note 2: This also assumes that you are familiar with swx itself. Please try running some examples using the standard swx gateway before trying to work with swxCI.

Installing swxCI

swxCI sits on top of both SWX and CodeIgniter (CI). Install those two applications first.

Download swxCI from the SVN, under Extras > swxCI.

Place swxCI_config.php, swxCI_lib.php & swxCI.php at the root of your website.

Finally copy the amfphp folder inside your CI controllers folder

Using swxCI

Configuring swxCI

The swxCI configuration settings are located in the swxCI_config.php file.

$use_services_folder : set to TRUE if you place your services in the SWX services folder. Set to FALSE if you want to use CI controllers for your services.

$swx_folder : the swx installation folder, normally 'php'

Setting the gateway

In Flash

To use the swxCI gateway, in your Flash code simply set the gateway parameter to the swxCI.php url.

var swx:SWX = new SWX();

swx.gateway = "http://<yoursite>/swxCI.php";

/* ... */

Using with the Service Explorer

To use the swxCI gateway in the Service Explorer, simply add the query string amf=true to the url:

http://<yoursite>/swxCI.php?amf=true

Note: When using the Controllers folder for services, the Service Explorer has no way to know the difference between swx methods and regular controller methods. It does not make sense to call non-swx methods through the Service Explorer and will likely cause problems.

Creating a swxCI service

Using Controllers

This is the preferred method, it keeps all your CI code in one place and make deployment easier (you basically never have to upload updates to the swx folder).

To create a swxCI service as part of a controller, simply add a method to your controller and use the return statement to send back data as the swx response:

class swx extends Controller 
{
	function getWordPressPages($parent_id=0)
	{
		$this->load->database();
		$q = $this->db->query("select * from wp_posts where post_type='page' and post_parent=?",array($parent_id));
		return $q->result();
	}
	
}

Using SWX Services folder

You have two options here.

You can have your service class inherit the Controller class to access the CI libraries, which is essentially the previous case and probably the cleanest option.

Or you can create a temporary Controller object and use it to access the CI libraries, like so:

class swx 
{
	function getWordPressPages($parent_id=0)
	{
		$CI = new Controller();
		$CI->load->database();
		$q = $CI->db->query("select * from wp_posts where post_type='page' and post_parent=?",array($parent_id));
		return $q->result();
	}
	
}

This last case works well if you want to add CI-enabled methods to some legacy swx service without modifying the other methods.

Project Status

This is an experimental add-on project to SWX and is provided as is with no support.

The current version of swxCI is known to work with the latest CI version (1.7.0).


Sign in to add a comment
Hosted by Google Code