【发布时间】:2012-01-05 17:13:22
【问题描述】:
我正在我的脚本中构建一些错误管理,需要一些关于如何使其正常运行的建议。
我很困惑如何将我的消息实际输出到结果函数中。我的脚本以 IF 语句开头,如果有问题,它将从我的错误函数中选择错误之一。 (我将如何具体选择哪个错误?)
所以首先我有:
if ($_GET)
{
// run function
} else {
return $this->error();
}
现在的错误函数:
private function error($errnum=1000) {
$data = array(
'error' => array(
'1000' => 'Required parameter is missing',
'1100' => 'Parameter not recognized',
'2000' => 'Currency type not recognized',
'2100' => 'Currency amount must be to 2 decimal places',
'3000' => 'Service currently unavailable',
'3100' => 'Error in service'
)
);
$this->result($data);
}
最后是结果函数:
private function result($data=array(),$type='XML') {
switch(strtolower($type)) {
case 'xml':
header("Content-type: text/html"); // Set header type to XML
$output = new SimpleXMLElement('<conv/>'); // Convert our php array to simpleXML
array_walk_recursive($data, array ($output, 'addChild'));
echo $output->asXML();
break;
}
exit;
}
【问题讨论】:
-
我不确定我是否理解 .. 你可以随意选择错误。
-
是的,但我不知道该怎么做。 (我对 PHP 很陌生,所以上面的一切都让我感到困惑)
-
如果您想使用错误 1100,您可以致电
$this->error(1100); -
我试过了,但它什么也没做。我认为我的某个函数中某处有错误
-
您从未在任何地方实际使用过
errnum参数。