Php Symfony$表单为空

Php Symfony$表单为空,php,json,forms,rest,symfony,Php,Json,Forms,Rest,Symfony,我已经构建了一个API GET函数。表单如下所示: <form action="/find" method="GET"> <input type="text" name="Title" id="Title" value=""> <input type="submit" value="Search"> </form> 找不到Google卷 我知道这个变量是空的,但是为什么呢?以下是功能代码: public function fin

我已经构建了一个API GET函数。表单如下所示:

<form action="/find" method="GET">
    <input type="text" name="Title" id="Title" value="">
    <input type="submit" value="Search">
</form>
找不到Google卷 我知道这个变量是空的,但是为什么呢?以下是功能代码:

public function findAction(Request $request)
{
    $form = $this->createForm(null, ['csrf_protection' => false])
        ->add('Title', TextType::class)
        ->add('Search', SubmitType::class)
        ->getForm();

    $form->handleRequest($request);

    var_dump($form->getData());

    if($form->isSubmitted() && $form->isValid()) {
        $json = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=".$form->get('Title')->getData());
        $response = json_decode($json, true);

        if(array_key_exists('items', $response)){
            return $this->render('BlogsiteBooksBundle:Pages:results.html.twig', [
                'items' => $response['items']
            ]);
        } else {
            return new Response('Google did not have any items', 400);
        }
    }

    return new Response('Google Book Not Found', 404);
}

默认情况下,表单希望通过POST发送数据,您需要将表单的方法设置为
GET

$this->createForm(null, ['csrf_protection' => false, 'method' => 'GET'])
    // ...
有关更多详细信息,请参阅

$this->createForm(null, ['csrf_protection' => false, 'method' => 'GET'])
    // ...