[英]PHP Notice: Undefined index
我正在使用Zendesk php類 ,以下函數用於刪除附件。
/**
* Delete one or more attachments by token or id
* $params must include one of these:
* 'token' - the token given to you after the original upload
* 'id' - the id of the attachment
*
* @param array $params
*
* @throws MissingParametersException
* @throws ResponseException
* @throws \Exception
*
* @return bool
*/
public function delete(array $params) {
if(!$this->hasAnyKey($params, array('id', 'token'))) {
throw new MissingParametersException(__METHOD__, array('id', 'token'));
}
$endPoint = Http::prepare(($params['token'] ? 'uploads/'.$params['token'] : 'attachments/'.$params['id']).'.json');
$response = Http::send($this->client, $endPoint, null, 'DELETE');
if ($this->client->getDebug()->lastResponseCode != 200) {
throw new ResponseException(__METHOD__);
}
$this->client->setSideload(null);
return true;
}
根據評論,運行此功能時需要令牌或ID。
我嘗試過使用id
$attachment = $client->attachments()->delete(array('id'=>'1187146218','token'));
然而,它一直在追逐異常
PHP Notice: Undefined index: token in /home/adam/web/srv11/public_html/vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Attachments.php on line 106
PHP Fatal error: Uncaught exception 'Zendesk\API\ResponseException' with message 'Response to Zendesk\API\Attachments::delete is not valid. Call $client->getDebug() for details' in /home/adam/web/srv11/public_html/vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Attachments.php:109
Stack trace:
#0 /home/adam/web/srv11/public_html/functions/support-attachment-delete.php(15): Zendesk\API\Attachments->delete(Array)
#1 {main}
thrown in /home/adam/web/srv11/public_html/vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Attachments.php on line 109
非常感謝您的幫助
你寫這篇文章的方式
array('id'=>'1187146218','token')
實際上給出了這樣一個數組:
array('id'=>'1187146218', 0 => 'token')
所以沒有'令牌'索引。 如果您改為,這應該有用
$attachment = $client->attachments()->delete(array('id'=>'1187146218','token' => NULL));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.