ReynierPM ReynierPM - 1 year ago 56
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?

Answer Source

As Cerad posted on the responses, you could use:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download