Answer the question
In order to leave comments, you need to log in
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()
]);
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question