Symfony Demo
  • Homepage
  • Search
  • Choose language
      English Français Deutsch Español Čeština Nederlands Русский Українська Română Português (brasil) Polski Italiano 日本語 Indonesia Català Slovenščina Hrvatski 中文 (中国)

This is a demo application built in the Symfony Framework to illustrate the recommended way of developing Symfony applications.

For more information, check out the Symfony doc.

Click on this button to show the source code of the Controller and template used to render this page.

Source code used to render this page

Controller codesrc/AppBundle/Controller/BlogController.php at line 161

/**
 * @Route("/search", name="blog_search")
 * @Method("GET")
 *
 * @return Response|JsonResponse
 */
public function searchAction(Request $request)
{
    if (!$request->isXmlHttpRequest()) {
        return $this->render('blog/search.html.twig');
    }

    $query = $request->query->get('q', '');
    $posts = $this->getDoctrine()->getRepository(Post::class)->findBySearchQuery($query);

    $results = [];
    foreach ($posts as $post) {
        $results[] = [
            'title' => htmlspecialchars($post->getTitle()),
            'summary' => htmlspecialchars($post->getSummary()),
            'url' => $this->generateUrl('blog_post', ['slug' => $post->getSlug()]),
        ];
    }

    return $this->json($results);
}

Twig template codeapp/Resources/views/blog/search.html.twig at line 1

©2026 - The Symfony Project

MIT License