Welcome Guest, Not a member yet? Register   Sign In
Merging a CI app with EE2
#1

[eluser]Nathan Pitman (Nine Four)[/eluser]
Hi all, I'm trying to merge a CI app which we have developed with a EE2 install such that the CI app can run off the version of CI which ships with EE2. Thus far I have EE2 installed and running with no problems and I have moved my index.php for my CI app into a sub folder. However when I try to access my CI app it's returning a similar error on all controllers:

Code:
Fatal error: Class 'Controller' not found in /home/ihasco/subdomains/dev/system/app/controllers/training.php on line 10

I'm guessing there's something I've missed in the CI index.php file perhaps or is it simply not possible to do what I'm trying... I had assumed that EE2 was just using a stable build of CI as it's base so would be able to point at that from my application...

Any help greatly appreciated! Smile
#2

[eluser]Darren Miller[/eluser]
Sounds like you're trying to extend Controller instead of CI_Controller, which is a v2 change
#3

[eluser]Nathan Pitman (Nine Four)[/eluser]
ah! You may be my savior! Yes... this app is running on CI 1.7.2!
#4

[eluser]Nathan Pitman (Nine Four)[/eluser]
Of course I'm now getting another error:

Code:
Fatal error: Call to undefined method CI_Controller::Controller() in /home/ihasco/subdomains/dev/system/app/controllers/training.php on line 15

So I'm guessing something here needs changing...

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
    +-----------------------------------------------------------------------+
    | CLASS: Training                                                           |
    +-----------------------------------------------------------------------+
    | Handles all aspects of online training                                |
    +-----------------------------------------------------------------------+
*/

class Training extends CI_Controller {

    function Training()
    {
        parent::Controller();
        $this->load->model('client');
        $this->load->model('messaging');
        $this->load->model('user');
        $this->load->model('result');
        $this->load->model('payperview');
        $this->load->helper('general_helper');
        $this->load->helper('url');
    }

    public function index()
    {

        // Defaults for preview
        $data = array();
        $data['debug'] = false;
        $data['view_only'] = false;
        $data['logged_in'] = false;
        ...

:?
#5

[eluser]Darren Miller[/eluser]
replace

<code>
parent::Controller();
</code>

with

<code>
parent::__construct();
</code>
#6

[eluser]toopay[/eluser]
also...
Code:
// replace
function Training()
// into
function __construct()
#7

[eluser]Nathan Pitman (Nine Four)[/eluser]
Brilliant, thanks guys. Smile
#8

[eluser]Nathan Pitman (Nine Four)[/eluser]
It's so almost there, I'm stuck with a one final challenge though, the .htaccess rewrites... I decided to go the route of switching things round and having the CI app as the default (index.php) and EE2 called via expressionengine.php. So both these files reside in the /public_html folder along with my .htaccess. What I wish to do is route all traffic for a specific set or controller names to the CI app and everything else to EE2, so I was thinking something along the lines of:

Code:
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} !^my\.domain\.com [NC]
RewriteCond $1 !webservices/
RewriteRule ^(.*)$ http://my.domain.com/$1 [R=301,L]

RewriteBase /
RewriteCond $1 !^(admin|cron|fst_reporting|playcatch|ppv|purchase|reporting|training|xml) [NC]
RewriteRule ^(.*)$ expressionengine.php/$1 [L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

But I'm not having any luck, this just throws a server error so I must be completely out of whack somewhere... :/
#9

[eluser]toopay[/eluser]
Its related with environment issues i believe. Working on this htaccess section, with some regex variation.
Code:
RewriteBase /
# If, you put CI package on subdirectory, specify it
# RewriteBase /ci_dir/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L]
# Play around/replace above line with each one line, below.
# RewriteRule ^(.*)$ index.php?/$1 [L]
# RewriteRule ^.*$ index.php/$1 [L]
# If, you put CI package on subdirectory, specify it
# RewriteRule ^(.*)$ ci_dir/index.php/$1 [L]
# RewriteRule ^(.*)$ /ci_dir/index.php/$1 [L]
# RewriteRule ^(.*)$ ci_dir/index.php?/$1 [L]
# RewriteRule ^(.*)$ /ci_dir/index.php?/$1 [L]
# RewriteRule ^.*$ ci_dir/index.php/$1 [L]
# RewriteRule ^.*$ /ci_dir/index.php/$1 [L]
#10

[eluser]Nathan Pitman (Nine Four)[/eluser]
Ok, I managed to get it working! Here's what I did:

1) Placed the CI app front end loader (index.php) in a sub folder (/app).
2) reverted back to having the EE front loader as index.php in the site root.
3) Modified my .htaccess file to read as follows:

Code:
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

# Rewrite requests for anything that's NOT a CI controller or physical file/folder to ExpressionEngine
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !(admin|cron|fst_reporting|playcatch|ppv|purchase|reporting|training|xml) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]

# Route everything else to CodeIgniter
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/index.php/$1 [L]

# Rejoice!

</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

Now I can specify controller names that need to be routed to CI and everything else get's routed to EE2! Smile

Hoorah!




Theme © iAndrew 2016 - Forum software by © MyBB