[swx] CodeIgniter for SWX

Ben Lagoutte ben.lagoutte at gozer.com.au
Sun Feb 24 21:30:48 PST 2008


Hi,

Been meaning to post that for a while but I haven't had a chance until now.

I've been using this for a while and it's working smoothly so far.

This is a (rather simple) way to use Code Igniter in a swx request.

I've basically trimmed down the code igniter front controller to the 
bare minimum, stripped down all the unnecessary stuff and compiled 
everything in a single file that you can include in your swx service 
method using a simple include_once(). It then gives you in your service 
method a $CI variable representing a stripped down controller for Code 
Igniter.

It removes the MVC concept entirely (I didn't really see the point in a 
swx call), though you can still load views in a variable if you want 
(usefull for instance when loading prepared email templates, etc).

What this does do is give you access to all the Code Igniter libraries 
from swx, (and by proxy from flash I guess). Most interestingly the DB 
and Active Records class, and also the Session class (which is very 
handy if your site is mostly a CI php site and you want a flash feature 
to be able to detect the logged in user and so on), but basically pretty 
much any CI class can be loaded. You can also load your own libraries.

Maybe a bit of a hack, maybe not as advanced as the Cake implementation 
for swx but if you like your code igniter or you need to work around an 
existing Code Igniter project, this might come handy.

The code is attached (can I send attachments in this list?), it's just 
one file.  Unzip and copy it to your swx/php folder

usage: 

   1. copy in swx/php/ folder (or anywhere you prefer).   
   2. set $system_folder variable in the swxCI.php file to the correct
      path to your CI system folder. (if you copy this in swx/php and
      your CI system folder & swx folder are both at the same level you
      don't need to change it)
   3. in your swx service, add: include_once("../swxCI.php")
   4. you now have a $CI variable in your service to access the whole CI
      library of functions.

    for instance:
    class AwesomeService
    {
        function getAwesome()
        {
           include_once("../swxCI.php");
          
    $CI->db->select('my_awesome_field')->from('my_awesome_table')->where(array('my_awesome_key'
    => 'awesome'));
           return $CI->db->get()->result();
        }
    }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/swx_osflash.org/attachments/20080225/3410a691/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swxCI.php.zip
Type: application/zip
Size: 2526 bytes
Desc: not available
Url : http://osflash.org/pipermail/swx_osflash.org/attachments/20080225/3410a691/attachment.zip 


More information about the swx mailing list