[en] Running CodeIgniter controller methods from external application

Gosh, this blog gets too tech­ni­cal 🙁 I guess I need to start wri­ting some kind of non-IT jour­nal here. You know, the teena­ge-pink-blog style 😉

Any­way, more for my own reference.

Code­Igni­ter is a nice and nonin­tru­si­ve PHP appli­ca­tion fra­me­work that I’ve grown to like and use it (also com­mer­cial­ly). The pro­blem is inte­gra­ting its MVC with exter­nal appli­ca­tions such as CMSes.

Here­’s a quick hack I’ve done to make this possible:

1. Cre­ate „exter­nal” sub­di­rec­to­ry under „sys­tem” direc­to­ry of Code­Igni­ter installation.
2. Pla­ce atta­ched files there.
3. Open „system/libraries/Loader.php” file and patch it like this: find line 681 and change

global $OUT;
$OUT->set_output(ob_get_contents());

to

global $OUT;
if (!isset($OUT)) $OUT = $GLOBALS['ci_external_out'];
$OUT->set_output(ob_get_contents());

4. For exam­ple of use, see atta­ched index.php file, basi­cal­ly to call a con­trol­ler method, just do this:

require_once 'ciexternal.php';
echo ci_external('controller', 'method');