从外部脚本笨get_instance功能(Codeigniter get_instance func

2019-09-30 20:40发布

我从外壳调用PHP文件,不在笨应用程序文件夹,所以我需要的应用程序的实例,我已经使用

<?php 

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

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

但我得到的错误:

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

Answer 1:

你已经做的唯一一件事就是试图创建一个实例......做到这一点,最好的方法是实际包括的index.php - 但抑制输出

下面应该工作

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

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


文章来源: Codeigniter get_instance function from external script