2013-02-06 167 views
1

我嘗試使用下面的代碼Zend框架日誌數據庫錯誤

$db = new Zend\Db\Adapter\Adapter(array(
'driver' => $config->database->adapter, 
'database' => $config->database->params->dbname, 
'username' => $config->database->params->username, 
'password' => $config->database->params->password 
)); 

$paypalLog = array(
'transactionId' => 'transactionId', 
'transactionType' => 'transactionType', 
'paymentType' => 'paymentType', 
'orderTime' => 'orderTime', 
'currencyCode' => 'currencyCode', 
'feeAmt' => 'feeAmt', 
'taxAmt' => 'taxAmt', 
'paymentStatus' => 'paymentStatus', 
'pendingReason' => 'pendingReason', 
'reasonCode' => 'reasonCode' 
); 

$writer = new Zend\Log\Writer\Db($db, 'paypal', $paypalLog); 
$logger = new Zend\Log\Logger(); 
$logger->addWriter($writer); 
$logger->info($transactionId, 
    $transactionType, 
    $paymentType, 
    $orderTime, 
    $currencyCode, 
    $feeAmt,   
    $taxAmt, 
    $paymentStatus, 
    $pendingReason, 
    $reasonCode); 
?> 

我不斷收到以下錯誤

Fatal error: Uncaught exception 'Zend\Log\Exception\InvalidArgumentException' with message '$extra must be an array or implement Traversable' in C:\xampp\htdocs\app\library\Zend\Log\Logger.php:236 Stack trace: #0 C:\xampp\htdocs\app\library\Zend\Log\Logger.php(333): Zend\Log\Logger->log(6, '2SH18664DB63910...', 'expresscheckout') #1 C:\xampp\htdocs\app\public\orderconfirm.php(124): Zend\Log\Logger->info('2SH18664DB63910...', 'expresscheckout', 'instant', '2013-02-06T10:4...', 'AUD', '0.52', '0.00', 'Completed', 'None', 'None') #2 {main} thrown in C:\xampp\htdocs\app\library\Zend\Log\Logger.php on line 236 

登錄PHP數據從貝寶調用數據庫返回任何幫助讚賞。

回答

0

我通過構建包含「額外」信息的數組和發送,進行了這方面的工作。

$data = array(
     'transactionId' => $transactionId, 
     'transactionType' => $transactionType, 
     'paymentType' => $paymentType, 
     'orderTime' => $orderTime, 
     'amt' => $amt, 
     'currencyCode' => $currencyCode, 
     'feeAmt' => $feeAmt, 
     'taxAmt' => $taxAmt, 
     'paymentStatus' => $paymentStatus, 
     'pendingReason' => $pendingReason, 
     'reasonCode' => $reasonCode 
     ); 

    $mapping = array(
     'message' => 'message', 
     'extra' => $data); 

    $writer = new Zend\Log\Writer\Db($db, 'paypal', $paypalLog); 
    $logger = new Zend\Log\Logger(); 
    $logger->addWriter($writer); 
    $logger->info($mapping);  
2

您正在錯誤地使用記錄器。

有它接受兩個paramters:

/** 
* @param string $message 
* @param array|Traversable $extra 
* @return Logger 
*/ 
public function info($message, $extra = array()) 
{ 
    return $this->log(self::INFO, $message, $extra); 
} 

你傳入$ TRANSACTIONTYPE作爲「額外」的字段,是不是probanly數組或對象traverable。

試試這個,數組應轉換爲日誌文件的字符串:

$logger->info(paypalLog); 
// or convert it to a string before logging.. it 
$logger->info(implode(',', $paypalLog)); 
+0

謝謝安德魯,這讓我朝着正確的方向前進 – LJT