2013-10-11 63 views
0

我用phpexcel在我的項目,如果我通過我的函數調用我的課,excel文件無法打開 我打電話給我的類:使用include_once,require_once時phpexcel錯誤?

$Model = loadModel('cpm','cpm',$this->registry); 

我的功能:

function loadModel($com='',$class_name='',$registry=null) { 
if (empty($com)){ 
    $com = 'admin'; 
} 
$filename = strtolower($class_name) . '.class.php'; 
$file = PATH_MODEL.DS.$com.DS.$filename; 

if (file_exists($file) == false){ 
    return false; 
} 
require_once($file); 
if($registry != NULL){ 
    $model = new $class_name($registry); 
}else{ 
    $model = new $class_name; 
} 
return $model; 

}

當我換到

/*require_once($file); 
if($registry != NULL){ 
    $model = new $class_name($registry); 
}else{ 
    $model = new $class_name; 
}*/ 
$model=true; 
return $model; 

它窩RK。在我的項目,我用自動加載:

function __autoload($class_name) { 
/*** get the component from the url ***/ 
$com = (empty($_GET['com'])) ? '' : $_GET['com']; 

if (empty($com)){ 
    $com = 'admin'; 
} 
$filename = strtolower($class_name) . '.class.php'; 
$file = PATH_MODEL.DS.$com.DS.$filename; 

if (file_exists($file) == false){ 
    return false; 
} 
requine_once ($file); 

}

我不知道這是原因。 我沒有在日誌中發現任何錯誤。 任何幫助,謝謝。

我發現如果我需要(一次)或包含(一次)文件在控制器中,excel文件將無法打開。

class excelController extends baseController { 
public function index(){ 
    require('abc.class.php'); 
    $this->registry->template->show('excel', false);  
} 

}

回答

0

這是可能的磁帶自動加載機與PHPExcel的自動加載衝突。請參閱開發人員文檔的第3.2節(標題爲「Lazy Loader」),以獲取有關使用spl_autoload_register()註冊自己的自動裝載器的建議,以便兩者可以共存