I
I
Ivan Antonov2015-10-15 15:35:26
symfony
Ivan Antonov, 2015-10-15 15:35:26

How to create a search form in Symfony2?

I created the form, here is the controller itself:

public function companiesAction(Request $request)
{
    $em = $this->getDoctrine()->getManager();
    $search = $this->createForm(new CompanyType(), null, array(
        'method' => 'GET'
    ));
    $search->handleRequest($request);
    $companies = $em->getRepository('AppBundle:Company')->findAll();
    return $this->render('AppBundle::companies.html.twig', [
        'companies' => $companies,
        'search' => $search->createView()
    ]);
}

how do i link the doctrine and the company search form? Is there a built-in capability for this in symfony?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Skobkin, 2015-10-15
@antonowano

You are doing something terrible.
What are built-in capabilities? What do you expect from Symfony?
Here you get all the companies from the table in general.
You can search by matching fields simply by calling the findBy() method on the repository.
Also, you didn't show your company search form. In general, the question is not clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question