I have this function:
public function chequearFabricanteAction(Request $request) { $em = $this->getDoctrine()->getManager(); $entities = $em->getRepository('AppBundle:FabricanteDistribuidor')->findOneBy( array( 'nombre' => $request->query->get('fabricante')['nombre'] ) ); $response['valid'] = true; if ($entities) { $response['valid'] = false; } return new JsonResponse($response); }
The function must be called from two different forms, and the only difference is the var request, which contains the value. In the first form it is: $request->query->get('fabricante')['nombre'] , and in the second it is $request->query->get('distribuidor')['nombre'] , so I ask is there a proper way to handle this:
if (isset($request->query->get('fabricante'))) { $nombre = $request->query->get('fabricante')['nombre']; } else { $nombre = $request->query->get('distribuidor')['nombre']; }
Is it correct? Is there a better one?
source share