我已经提出了一个curl请求。我把卷曲指令放在一个类函数中:无法从变量中获取数据
class Curly {
var $data;
function GetRequest($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$this->data = curl_exec($ch);
curl_close($ch);
//this is what i was missing --> return $this->data;
}
我把数据库查询放在另一个类的函数中。
include('class.curly.php');
class mongoSearchForInfoOnEsd {
public function getEsdsFbInfo($esdID) {
$mongoApiKey = "xx";
$requestParams= "xx";
$url = "xx";
$fbInfo = (new Curly)->GetRequest($url);
//this is what i was missing --> return $fbInfo;
}
在index.php,从一个网络挂接的HTTP POST即将通过,在这种通过一些字符串解析,获取2个IDS被处理。然后我发送其中一个id到mongodb curl请求,一切都很顺利。正确的响应回来了,我只知道curly类中的var_dump的var_dump的这个b/c ....但是在索引文件中,我努力从var中获取数据并分配它的值我想要的任何变量。
如何获取数据?我知道它在那里,但在哪里? 我很困难。
# get ytID from http post
#get EsdID from http post
$httpPostData = file_get_contents('php://input');
$postDataDecoded = urldecode($httpPostData);
$ytID = substr($postDataDecoded, strpos($postDataDecoded, "docid=") + strlen("docid="),);
$esdID = substr($postDataDecoded, strpos($postDataDecoded, "m\": \"") + strlen ("m\": "),;
*$esdData = (new mongoSearchForInfoOnEsd)->getEsdsFbInfo("$esdID");*
$obj = json_decode($esdData, true);
echo $obj;
OK,我已经添加了回报,我可以看到数据,但没有操作上返回的数据工作。
编辑--->把这两个班的回报,现在它的全面运作。
也许你需要'GetRequest()'返回''? – lazyhammer 2013-03-23 15:01:21
这正是我刚才说的.. – 2013-03-23 15:02:48