我正在使用幫助函數來驗證Codeigniter中的XML。幫助程序中定義的函數未在控制器中找到
我的助手功能在xml_validation_helper.php
定義如下:
/**
* Function to generate a short html snippet indicating success
* or failure of XML loading
* @param type $xmlFile
*/
function validate_xml($xmlFile){
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->validateOnParse = true;
$dom->load($xmlFile);
if (!$dom->validate())
{
$result = '<div class="alert alert-danger"><ul>';
foreach(libxml_get_errors() as $error)
{
$result.="<li>".$error->message."</li>";
}
libxml_clear_errors();
$result.="</ul></div>";
}
else
{
$result = "<div class='alert alert-success'>XML Valid against DTD</div>";
}
return $result;
}
我用它在我的控制器(特別是在index
法)和如下:
function index() {
$this->data['pagebody'] = "show_trends";
$this->load->helper("xml_validation");
$this->data['pokedex'] = display_file(DATA_FOLDER ."/xml/pokedex.xml");
$pokedexResult = validate_xml($this->data['pokedex']);
$this->data['gameSales'] = display_file(DATA_FOLDER . "/xml/sales.xml");
$gameSalesResult = validate_xml($this->data['gameSales']);
$this->render();
}
然而,我仍然收到一個「Fatal error: Call to undefined function validate_xml() in C:\xampp\htdocs\project\application\controllers\show_trends.php on line 15
錯誤,儘管我可以清楚地加載文件。我甚至嘗試將該函數移動到與index
方法相同的文件中,但它仍然表示它是未定義的。
爲什麼我得到這個錯誤,即使這個函數是明確定義的?