Posts tagged integration
Integrating CodeIgniter with AMFPHP
Nov 2nd
A while back i spent an evening hacking away at the CodeIgniter source code. I was desperate to use it as a library, as opposed to a framework. I don’t use PHP with HTML. I did for a little bit, but personally i found that HTML and CSS were the biggest load of shit languages ever to plague my existence! Sorry. Once i was introduced to Flash and Flex, i said “to hell with HTML and it’s ugly sister CSS! I’m becoming a banner-maker!”. Not quite… i’ve never made a banner – even though that’s like totally the whole point of Flash, dude… (insert stupid programmer comments here).
Ahem. Back to the point. So when i started writing Flex apps and using AMFPHP for my remoting, i desperately wanted a nice concise, easy-to-use, well documented library. Enter CodeIgniter by Rick Ellis. Although CI is actually a MVC framework for PHP, i decided i was going to turn it into a library! (and what a ballache that was).
Below is the massive, complex, obfuscated script I wrote to turn it into a library. Notice how the script seems to drip with programming excellence:
<?php if (!defined('BASEPATH')) define ("BASEPATH", "../CodeIgniter/system/"); if (!defined('APPPATH')) define ("APPPATH", "../CodeIgniter/system/application/"); if (!defined ("EXT")) define ("EXT", ".php"); require_once (BASEPATH."codeigniter/Base5.php"); require_once (BASEPATH."libraries/Controller.php"); require_once (BASEPATH."codeigniter/Common.php"); ?>
Crazy huh? Haha. Essentially, all this script does is fuck with some of the framework architecture and allow the package to be required in PHP. See the usage below:
<?php
require_once("CodeIgniter.php"); // the path to your CodeIgniter.php script as described above
class AMFPHP_CI_Integration { function __construct() // PHP constructor { parent::Controller(); // Extend the functionality of the CI Controller class } }
?>
And that’s it! Flimsy and hackerish, i know, but hey… It works
Any queries or suggestions are most welcome!