[en] Running CodeIgniter controller methods from external application

Gosh, this blog gets too technical 🙁 I guess I need to start writing some kind of non-IT journal here. You know, the teenage-pink-blog style 😉

Anyway, more for my own reference.

CodeIgniter is a nice and nonintrusive PHP application framework that I’ve grown to like and use it (also commercially). The problem is integrating its MVC with external applications such as CMSes.

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

1. Create „external” subdirectory under „system” directory of CodeIgniter installation.
2. Place attached 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 example of use, see attached index.php file, basically to call a controller method, just do this:

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

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *