Newer
Older
namespace SGalinski\TypoScriptReferenceFrontend\Controller;
/* *
* This script belongs to the TYPO3 Flow package "SGalinski.TypoScriptReferenceFrontend".*
* *
* */
use TYPO3\Flow\Annotations as Flow;
class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
/**
* @return void
*/
public function indexAction() {
$jsonAttributes = $this->curl_download('http://127.0.0.1:8000/api/attributes');
$this->view->assign(
'foos', [
'bar', $jsonAttributes
]
);
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
}