I am building a series of calls to an external API.
I have in the controller a simple function to open a connection
public function openConnection()
{
$jsonObject = Yii::app()->curl->post( $this->auth_uri , $this->data);
$obj = json_decode($jsonObject);
$ok = $obj->response->status;
if ($ok == "OK") {
$token = $obj->response->token;
return $token;
} else { return 'Error';}
}
I also have in the controller a function to make a CURL GET call to the API
public function actionGetData()
{
// Authorize
$token = openConnection();
$auth = array('Authorization:'.$token);
$jsonObject = Yii::app()->curl->setOption(CURLOPT_HTTPHEADER, $auth)->get($url);
$obj = json_decode($jsonObject);
$ok = $obj->response->status;
if ($ok == "OK") {
$count = $obj->response->count;
$start_element = $obj->response->start_element;
$num_elements = $obj->response->num_elements;
}
$this->render('result', array('msg' => $ok,'token' => $token,));
}
[b]
For some strange reason the call to openConnection() fails and the system hangs.
If I put it all in one routine "actionGetData()" then it works fine.
[/b]
What I am doing wrong?
Should I be able to define a private or public $var in the controller and reference it as $this->$token ?
I setup public varialbles for $auth_uri and it works fine but it is a constant…I cannot re-assign it a value.
I must be missing something really obvious.
Would I be better off making this a module or extention rather than just a controller?
Thanks !