We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Custom CI Controllers

Development and Programming

Paramore's avatar
Paramore
40 posts
15 years ago
Paramore's avatar Paramore

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.

       
Paramore's avatar
Paramore
40 posts
15 years ago
Paramore's avatar Paramore

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 */
       
Frans Cooijmans's avatar
Frans Cooijmans
36 posts
15 years ago
Frans Cooijmans's avatar Frans Cooijmans

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.