So, While waiting for the much anticipate Expression Engine, we had to have a non-custom solution to a client friendly CMS. It turns out its actually really easy to make wordpress and codeigniter play in the same sandbox together – with almost no configuration.
Basically what you do is install wordpress and get it running on its own, then dump in your ci setup, replacing the wordpress index file with your codeigniter one.
Next, modify the index.php (Codeigniter bootstrapper) and require in the wp-load.php file (wordpresses bootstrapper)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /* |-------------------------------------- | LOAD THE FRONT CONTROLLER |-------------------------------------- | | And away we go... | */ require_once 'wp-load.php'; require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; /* End of file index.php */ /* Location: ./index.php */ |
This is pretty much it.. the only other thing you need to do is to use the wp_head() to pull in all the css/js that are required from any modules.
Because all of wordpress is run from the global space with functions (as apposed to a main class like CI) all the functions are available to you in your templates and views in ci..
Now, you have a wp-admin with all your content and your client access powering content for a 100% CI front end.
What we are doing (thanks Easily Amused for the idea) is building categories for each area (like a weblog in EE) and letting our customer add posts and add them to that category to go on that page… Like a homepage cateory, the latest post gets pulled in
The following code is in my view! (sorry about the crappy formatting, this site is wordpress and it freaks out when putting wp code into posts…
—
Homepage Only Feed
1 2 3 4 5 6 7 8 9 | query_posts('numberposts=1&cat=3');
while ( have_posts() ) : the_post()
<h3><?php the_title() ?></h3>
<p><?php the_content(); ?></p>
<p>Updated <?php the_time('l, F jS, Y') ?></p>
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; ?>
<h3>Flickr Feed Plugin</h3>
<?php widget_flickrRSS(array()); ?> |
There is a lot more to be done, next step i will be working on is a CI library that uses the WP users/auth, so it can be portable, as well as some kind of module in WP that has easy access to CI Models & Controllers like doing an AJAX call or AMF Call
What
This ‘library’ for lack of a better description allows designers to use libraries of high-res images anywhere in the site, at any size, without having to pre-define or pre-scale your images. It can also be used on the fly with user uploaded photos in a gallery setting.
Why
Other alternatives I have found in both codeigniter and other frameworks/cms’s like Drupal, EE, and WordPress require the administrators to pre-define set image sizes like thumbnail, medium, large. While this makes sense for a new site, it can be an issue if you want to redesing and start using a different size for thumbnails, previews etc.
Basic Usage Overview
To use the ‘library’, all you need to do is set your img tag source to point to the controller with a few pre-defined uri segments.
Image Tag: <img src=”/img/size/o/folders_your_image_is_in-your_image.jpg/w/240/h/160/m/auto” />
* If you arn’t using .htaccess to mask your index.php.. change the path to index.php/img/size…..
Sample site using library: http://www.synlawn.com/gallery
Features
- Fully customizable with little work
- Can support any directory depth in any location (does not need to be web accessible)
- Automatically caches called images in their original directory at called size so it only processes once
- Can be dropped into any CI installation – It was even originally written as a Matchbox module
- Maintains your image heirarchy and file name in source (for SEO) and keeps images available for external reference.
- Uses default codeigniter img_library, nothing else to install (unless you do not have imagemagick, netpbm, gd, or gd2)
- Uses a default ‘error/not-found’ image so you can stick a site logo on a high res image to use anywhere in case of an error (no image-not-found issues)
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('BASEPATH', realpath(dirname(__FILE__)).'/'.$system_folder.'/');
This is more of a repost of my wiki page on Codeigniter’s site, but i needed filler content for my first few postings on my site.
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
What it does
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 – and you can drop this into your existing setup.
How??
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. – Then you create an AMFPHP Services in the services folder that just extends your Codeigniter models, and gives you full access
Full Working Example
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 (Wade Arnold) and a sample product mysql table.
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.
And away we go: Instructions / Explanation of whats going on
- Download Codeigniter and AMFPHP (or pull apart the link above)
- Make sure Codeigniter works as expected before moving forward
- Put the unzipped amfphp package into your libraries folder
- Create your amf_gateway.php in ‘controllers’
This file replaces the need for gateway.php
setup netConnection to ‘/index.php/amf_gateway’
class Amf_gateway extends Controller { public function __construct() { parent::Controller(); //Start our library (keep reading the tutorial) $this->load->library('amfci'); //Set new include path for services ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . AMFSERVICES); } //startup the amf gateway service public function index() { $this->amfci->service(); } }
- Create a standard Codeigniter model or use an existing one
- Drop in the amfci_db.php file provided into ‘libraries/amfphp/services/amfci_db.php’
- Create AMFPHP Service in ‘libraries/amfphp/services’ folder using the template provided
This file is a service for AMFPHP – called from flash
This extends your existing model to give flash access to all its methods
//Load CI DB Instance since we are not coming through index.php require_once('amfci_db.php'); // Use this path if you are using a module (ie, MatchBox) // require_once(AMFSERVICES.'/../../../modules/test_shop/models/product_model.php'); // Use this path if you are using standard install require_once(AMFSERVICES.'/../../../models/your_model.php'); class your_model_service extends your_model { //Since extending your_model, all existing methods are available //New Methods public function yourNewMethod() { $something = array(); //Create array to send to flash return $something; } }
Add the amfci.php library to your library folder 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->gateway, and settign the needed options
This file is the new amfphp library for CI
It it loaded from the amf_gateway controller, and binds all of it together
class Amfci { public $gateway; public $CI; public function __construct() { $this->CI = get_instance(); require realpath(dirname(__FILE__))."/amfphp/globals.php"; require realpath(dirname(__FILE__))."/amfphp/core/amf/app/Gateway.php"; define('AMFSERVICES', realpath(dirname(__FILE__))."/amfphp/services"); $this->gateway = new Gateway(); $this->gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1"); $this->gateway->setLooseMode(); $this->gateway->setErrorHandling(E_ALL ^ E_NOTICE); $this->gateway->setClassMappingsPath(AMFSERVICES.'/vo'); $this->gateway->setClassPath(AMFSERVICES); if(PRODUCTION_SERVER) { //Disable profiling, remote tracing, and service browser $this->gateway->disableDebug(); } } public function service() { $this->gateway->service(); } }
Connect and call from flash
package com.page12.hello_world { import flash.display.MovieClip; import fl.events.*; import flash.events.*; import flash.net.NetConnection; import flash.net.Responder; import flash.net.ObjectEncoding; public class Main extends MovieClip { private var gateway:String = "/index.php/amf_gateway"; private var connection:NetConnection; private var responder:Responder; public function Main() { send_btn.addEventListener(MouseEvent.CLICK, sendData); responder = new Responder(onResult, onFault); connection = new NetConnection; //connection.objectEncoding = ObjectEncoding.AMF3; connection.connect(gateway); } public function sendData(e:MouseEvent):void { var params = server_txt.text; response_txt.text = 'Send '+server_txt.text+' to server'; connection.call("hello_world_service.say", responder, params); } private function onResult(result:Object):void { response_txt.text = String(result); } private function onFault(fault:Object):void { response_txt.text = String(fault.description); } } }

