Skip to content
Snippets Groups Projects
Commit cf456f36 authored by damjan's avatar damjan
Browse files

[FEATURE] Using curl in controller to get attributes from REST API

parent e3c5bd89
No related branches found
No related tags found
No related merge requests found
......@@ -10,14 +10,58 @@ namespace SGalinski\TypoScriptReferenceFrontend\Controller;
use TYPO3\Flow\Annotations as Flow;
class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
/**
* @return void
*/
public function indexAction() {
$this->view->assign('foos', array(
'bar', 'baz'
));
$jsonAttributes = $this->curl_download('http://127.0.0.1:8000/api/attributes');
$this->view->assign(
'foos', [
'bar', $jsonAttributes
]
);
}
function curl_download($Url) {
// is cURL installed yet?
if (!function_exists('curl_init')) {
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
// curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// // User agent
// curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
// curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'istype: 1'
));
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment