Stefano Maglione
Stefano Maglione

Reputation: 4150

Codeigniter get_instance function from external script

I am calling from the shell a php file that is not in the Codeigniter application folder and so I need an instance of the application and I have used

<?php 

const BASEPATH = "/"; 
require './system/core/Controller.php';

$CI =& CI_Controller::get_instance();
var_dump($CI->load->helper('url'));

but I get error:

PHP Notice:  Trying to get property 'load' of non-object

Upvotes: 1

Views: 1204

Answers (1)

Atural
Atural

Reputation: 5439

the only thing you've to do is to try to create an instance... The best way to do this is to actually include the index.php - but to suppress the output

the following should work

ob_start();
require_once('./index.php');
ob_end_clean();

var_dump($CI->load->helper('url'));

Upvotes: 4

Related Questions