未定义的索引 php中_PHP注意:未定义的索引

本文档描述了在使用Zendesk PHP客户端库删除附件时遇到的一个错误,即由于参数传递方式不正确导致的`Undefined index: token`异常。解决方案是正确设置参数数组,确保包含有效的ID和(如果需要)令牌。通过将ID和令牌作为键值对传递,而不是单独的数组元素,可以避免该问题。
摘要由CSDN通过智能技术生成

我正在使用

Zendesk php class,以下功能用于删除附件.

/**

* 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));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值