Php 从控制器中的codeigniter库获取$response

Php 从控制器中的codeigniter库获取$response,php,codeigniter,Php,Codeigniter,所以我在codeigniter库中使用了一个stripe类。其中一项功能以: $response = curl_exec( $req ); curl_close( $req ); return $response; 我想知道如何在请求数据的控制器中获得$echo响应 在我的控制器中,我有以下功能: $this->load->library('stripe'); $this->stripe->charge_card($amount, $card, $desc); ec

所以我在codeigniter库中使用了一个stripe类。其中一项功能以:

$response = curl_exec( $req );
curl_close( $req );
return $response;
我想知道如何在请求数据的控制器中获得$echo响应

在我的控制器中,我有以下功能:

$this->load->library('stripe');

$this->stripe->charge_card($amount, $card, $desc);

echo $response;
现在,控制器抛出一个错误,表示
$response
未定义。我也尝试过:
echo$this->stripe->response()

因此,如果库
返回$response
我如何在最初发出请求的控制器中回显它?例如(
echo$response;

您需要在变量中捕获函数的返回值:

$response = $this->stripe->charge_card($amount, $card, $desc);
那就做吧

echo $response;
因此,您的新代码应该如下所示:

$this->load->library('stripe');
$response = $this->stripe->charge_card($amount, $card, $desc);
echo $response;

所以我需要更换
$this->stripe->charge\u卡($amount,$card,$desc)带有
$response=$this->stripe->charge\u card($amount,$card,$desc)避免每次交易向客户收取两次费用?你可能想在回答中澄清这一点。供日后参考!:)谢谢。@user3367639是的。您可以用上面的代码替换该行。