0

我正在尝试使用 Google Books API,但它显示“标题”的未定义索引,因为我正在尝试搜索书名并将结果显示在树枝中。

我的控制器:-

public function googlebooksAction($id)
    {
        $client = new Client();
        $response = $client->get('https://www.googleapis.com/books/v1/volumes?q=id='.$id);
        $data = $response->json();
        $books = $data['title'];
        return $this->render('ReviewerReviewBundle:Google:googlebooks.html.twig',
            array(
               'title' => $books
            ));
    }

我的树枝文件:-

{% extends "::base.html.twig" %}

{% block title %}{{ book.volumeInfo.title }}{% endblock %}

{% block body %}
<h1>Google Books</h1>
    {% for book in books %}
        <article>{{ book.volumeInfo['title'] }}</article>
    {% endfor %}
{% endblock %}
4

0 回答 0