duanfu6160 2016-11-30 10:33
浏览 44
已采纳

codeigniter使用rest将数据传递到外部站点

OK in plain PHP I use the following to pass data to a GET

file_get_contents('https://ws.mysite.com/some.svc/here?userID=' . $session_id . '&score=' . $percentilescore . '&assessmentID=' . $testID . '&assessmentTitle=some');

I now want to apply this same piece of code to my CI project.

This Is how I have tried.

private function getResults()
    {

        $score = $this->actions->getSentEmailCount();
        $percentilescore = $percentile = $this->actions->getPercentile($score);
        $testID = '134';
        $percentile = $this->actions->getPercentile($score);
        $time = $this->input->get('time');
        $timemath = 60000;
        $timeinmseconds =  $time * $timemath;



        $adddata = array(
            'uniID' => '5',
            'testName' => 'some',
            'testID' => $testID,
            'total' => '10',
            'correct' => $score = $this->actions->getScore(),
            'percent' => $score = $this->actions->getScore(),
            'dateTaken' => date('Y-m-d H:i:s'),
            'timeSpent' => $timeinmseconds,
            'userID' => $session_id,
        );

        $this->actions->add_record($adddata);
        return $this->load->view('client/results', $data);

        file_get_contents('https://ws.mysite.com/123.svc/some?userID=' . $session_id . '&score=' . $percentilescore . '&assessmentID=' . $testID . '&assessmentTitle=some');

    }

It is not posting the data any idea why and how I should do it in CI ?

  • 写回答

1条回答 默认 最新

  • duaj39673 2016-11-30 10:43
    关注

    return should be the last statement in the function because it's immediately ends execution of the current function. Just put file_get_contents before return:

    file_get_contents('https://ws.mysite.com/123.svc/some?userID=' . $session_id . '&score=' . $percentilescore . '&assessmentID=' . $testID . '&assessmentTitle=some');
    
    $this->actions->add_record($adddata);
    return $this->load->view('client/results', $data);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频