2015-09-06 20 views

回答

1

您可以使用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 }}