Using EE 2.0
I am building a simple handler script that will consume some XML data post to the script. The script will need access to the ExpressionEngine database. My best case scenario is that I could create a CI controller that is accessible via the standard CI controller/method URI scheme and it would have access to all the standard CI libraries at the very least and preferably the EE libraries as well. How much hacking is required to make this happen and is it even feasible? My goal here is to minimize the amount of logic/configuration duplication that has to happen (i.e. reusing the EE config files to access the DB, etc.)
Or, is there a better way? I don’t need a backend or anything as the sole purpose of this script will be to consume the post data.
Thanks for your insight.
OK, so I’ve gotten a little further so I’ll post what I’ve done to help anyone else out:
In the front-end index.php, you’ll need to comment out the routing overrides in lines 95-97. All this does is allow code igniter to check for custom controllers prior to sending the request to EE.
Then, you can create your custom controllers in the system/expressionengine/controllers folder and call them with the standard CI URL scheme: http://www.mysite.com/index.php/mycontroller/mymethod/
Now, in your controller constructor, you’ll need to add the initialization code to get all the CI and EE libraries. Here is the barebones controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Test Controller
*
* @package default
* @author Jesse Bunch
**/
class Test extends Controller {
/**
* Construct
*/
function Test()
{
parent::Controller();
// Calls the EE & CI initialization
$this->core->_initialize_core();
$this->EE =& get_instance();
}
// --------------------------------------------------------------------
/**
* Index
*/
function index()
{
$this->load->view('test');
}
}
/* End of file test.php */
/* Location: ./system/expressionengine/controllers/test.php */you can also create a subfolder in your webroot with a specialized index.php that removes the EE controller override. In that way you are sure not to corrupt the standard installation.
With the latest version (2.1.*) it should also be possible to create a separate application folder for your custom controllers.
You would have to change the line
// Path to the “application” folder define(‘APPPATH’, $system_path.’expressionengine/’);
in your index.php to something else. Haven’t tested it though.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.