Since everyone has been so eager to jump into using CodeIgniter in Expression Engine 2.0, this thread has been created as a sort of informal discussion area for people to post and discuss helpful tips and tricks they have learned in using CodeIgniter inside Expression Engine.
CodeIgniter can now be used in the following components of EE:
MODULES (most recommended)
—Full-featured components, including Control Panel functions and front-end functions. Managing templates, database, etc. This is recommended if you need a lot of features and would like to follow the traditional CI model/view/controller style setup. Easy to call from EE templates. Example: {exp:module_name:function_name}
PLUGINS
—Focusing on modifying template code and front-end work
EXTENSIONS
—Tweaking the functionality of the Control Panel and hooks in the system
From what I have seen, the most flexible implementation of CodeIgniter will occur in modules.
————————————————————————————————————————————————————————————————————-
NOTE: All third-party add-ons must be placed inside the folder of /system/expressionengine/third_party
————————————————————————————————————————————————————————————————————-
Modules:
Modules will enable you to follow the traditional CodeIgniter MODEL-VIEW-CONTROLLER style setup, and offer the greatest flexibility.
With minor amount of work, you should be able to convert a basic CI application to EE by making it a module and following the instructions below. You can then call your CodeIgniter methods directly from your templates!
To load CodeIgniter helpers/libraries into your module, you simply do the following inside your function:
$this->CI =& get_instance();
$this->CI->load->helper('url');The module folder must be named as module_name.
Modules require several files to operate properly. Make sure you have created the following files in your module_name folder:
/mcp.module_name.php - Your back end control panel functions for submission and/or management of content
/mod.module_name.php - This is the core module file, and will contain the methods that your EE tags will be calling. It is used for front-end stuff like form processing and the displaying of content from the database. (example: {exp:module_name:function_name}
/upd.module_name.php - Update file for installing/uninstalling/updating your module from the EE database, and also for installing/uninstalling/updating your own custom tables
/language/english/lang.module_name.php - Language definitions for your application to use.
Once you have your module set up, it basically acts as a mini CodeIgniter “application” folder similar to a regular CodeIgniter installation. You can create a /view folder to hold your view files, and a /models folder to hold your models. Note: The view files will be used in the Control Panel *only*. Your EE templates act as your front-end “views”.
Several of these files require special code to be detected inside Expression Engine. Please refer to the Expression Engine 2.0 module development documentation here for details on all the requirements:
http://expressionengine.com/public_beta/docs/development/tutorial.html
————————————————————————————————————————————————————————————————————-
Plugins:
To use CodeIgniter inside a Plugin, you can create a normal style controller class/function structure. To load CodeIgniter helpers/libraries into your plugin, you simply do the following inside your function:
$this->CI =& get_instance();
$this->CI->load->helper('url');Plugins need to be named in the format of pi.plugin_name.php. Folder name should be as plugin_name. You will need to add the appropriate EE plugin code for it to be detected inside EE.
<?php
$plugin_info = array(
'pi_name' => 'Test\'s Plugin',
'pi_version' => '1.0',
'pi_author' => 'Author Name',
'pi_author_url' => 'http://www.google.com',
'pi_description' => 'This is a test to see how the plugin system works.',
'pi_usage' => Test_plugin::usage()
);
class Test_plugin
{
var $return_data = "";
function Test_plugin()
{
}
// This function holds the usage documentation
function usage()
{
ob_start();
?>
This is where our simplified documentation will go.
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
}It would be helpful if everyone could share a few of their own tips on how they were able to implement CodeIgniter software in Expression Engine.