dtlc84438 2019-02-26 07:23
浏览 62
已采纳

Guzzle删除冗余请求方法

Is there any method for remove redundant writing request method?

so at this moment my code looks like this

$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());

as you can see I must rewrite the same code. can I make that be more simple?

  • 写回答

1条回答 默认 最新

  • dtt27783 2019-02-26 07:57
    关注

    What you can do is you can simplify the calls:

    $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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因