0
从Symfony2中的URL导入Json内容并将其输出到树枝模板中的最佳做法是什么?从symfony2中的URL导入JSON
$url = https://btc-e.com/api/2/btc_usd/ticker
从Symfony2中的URL导入Json内容并将其输出到树枝模板中的最佳做法是什么?从symfony2中的URL导入JSON
$url = https://btc-e.com/api/2/btc_usd/ticker
您可以使用file_get_contents
检索json内容,然后将其传递给视图。你的控制器可能看起来像:
//…
class FooController extends Controller
{
//…
public function getJsonContentAction()
{
$jsonContent = file_get_contents("https://btc-e.com/api/2/btc_usd/ticker");
return $this->render(
'AppBundle:Foo:bar.html.twig', // Edit it to insert the view you want to render
[
'ticker' => json_decode($jsonContent),
]
);
}
}
,然后在树枝模板,以显示它:
{{ ticker.ticker.high }}
没有人回答? – perception30