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 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示