无法获取CI对象的实例以在线程类的run((函数中使用模型。
线程启动正常,但无法调用模型函数 请帮忙!!
class Clinical extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('directory');
}
public function index()
{
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set("max_execution_time", '0');
ini_set('memory_limit', '1024M');
$dirList = scandir('../clinicalTrial/');
$data["dirList"] = $dirList;
$this->load->view('clinical',$data);
}
public function import()
{
$folder = $_POST["folder_name"];
$dir = directory_map('../clinicalTrial/'.$folder);
$key = $folder;
$myThreadObj = new ClinicalThread($dir,$key);
var_dump($myThreadObj->start());
echo "Import Done";
exit;
}
}
class ClinicalThread extends Thread
{
public $dir = array();
public $key = "";
public function __construct($dir,$key)
{
$this->dir=$dir;
$this->key=$key;
}
function run()
{
$CI = & get_instance();
echo "";
print_r($CI);
exit;
if(!empty($this->dir))
{
foreach($this->dir as $file)
{
$CI->ct->extract($this->key,$file);
}
}
}
}
您不能在线程中调用框架的模型函数,因为它不会在线程内加载框架引擎。
请在线程内使用直接数据库连接与数据库通信。