ReynierPM ReynierPM - 24 days ago 4x
PHP Question

Check whether parameter exists or not in the request

I have this function:

* @Route("/chequearFabricanteDistribuidor", name="chequearFabricanteDistribuidor", condition="request.headers.get('X-Requested-With') == 'XMLHttpRequest'")
* @Method("GET")

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 needs to be called from two different forms and the only different is the request var that holds the value. In the first form is:
while in the second is
so I'm asking if the right way to handle this could be:

if (isset($request->query->get('fabricante')))
$nombre = $request->query->get('fabricante')['nombre'];
$nombre = $request->query->get('distribuidor')['nombre'];

Is this right? Exists a better one?


As Cerad posted on the responses, you could use: