Guzzle 删除冗余请求方法
Guzzle remove redundant request method
有什么方法可以去除多余的写请求方法吗?
所以现在我的代码看起来像这样
$response['slide'] = $this->_client->request('GET', 'artikelc/slidelimit',[
'query' => [
'auth-apikey' => $this->keyauth
]
]);
$this->data['slide_grab'] = json_decode($response['slide']->getBody()->getContents());
$response['subpost'] = $this->_client->request('GET', 'artikelc/subpost',[
'query' => [
'auth-apikey' => $this->keyauth
]
]);
$this->data['subpost_grab'] = json_decode($response['subpost']->getBody()->getContents());
$response['newsone'] = $this->_client->request('GET', 'artikelc/newsone',[
'query' => [
'auth-apikey' => $this->keyauth
]
]);
$this->data['newsone_grab'] = json_decode($response['newsone']->getBody()->getContents());
如您所见,我必须重写相同的代码。我可以让它更简单吗?
你能做的就是简化调用:
$options = [
'query' => [
'auth-apikey' => $this->keyauth
]];
$this->data['slide_grab'] = $this->_client->get('artikelc/slidelimit', $options)->json();
$this->data['subpost_grab'] = $this->_client->get('artikelc/subpost', $options)->json();
$this->data['newsone_grab'] = $this->_client->get('artikelc/newsone', $options)->json();
有什么方法可以去除多余的写请求方法吗?
所以现在我的代码看起来像这样
$response['slide'] = $this->_client->request('GET', 'artikelc/slidelimit',[
'query' => [
'auth-apikey' => $this->keyauth
]
]);
$this->data['slide_grab'] = json_decode($response['slide']->getBody()->getContents());
$response['subpost'] = $this->_client->request('GET', 'artikelc/subpost',[
'query' => [
'auth-apikey' => $this->keyauth
]
]);
$this->data['subpost_grab'] = json_decode($response['subpost']->getBody()->getContents());
$response['newsone'] = $this->_client->request('GET', 'artikelc/newsone',[
'query' => [
'auth-apikey' => $this->keyauth
]
]);
$this->data['newsone_grab'] = json_decode($response['newsone']->getBody()->getContents());
如您所见,我必须重写相同的代码。我可以让它更简单吗?
你能做的就是简化调用:
$options = [
'query' => [
'auth-apikey' => $this->keyauth
]];
$this->data['slide_grab'] = $this->_client->get('artikelc/slidelimit', $options)->json();
$this->data['subpost_grab'] = $this->_client->get('artikelc/subpost', $options)->json();
$this->data['newsone_grab'] = $this->_client->get('artikelc/newsone', $options)->json();