How can I get a parameter that comes from the get method from the controllers file in php

0

I have this url which sends the parameter id by means of the get method, but when I want to receive it through the controller, it tells me that it does not exist.

  

link

 public function getUpdate(){

        global $pdo;
        $id = $_GET['id'];
        $sql = "SELECT * FROM users WHERE id=:id";
        $query = $pdo->prepare($sql);

        $query->execute([
            'id' => $id
        ]);

        $row = $query->fetch(\PDO::FETCH_ASSOC);
        $nameValue = $row['name'];
        $emailValue = $row['email'];

        return render('../views/admin/update.php', ['nameValue'=>$nameValue, 'emailValue'=>$emailValue]);

    }

Then I put on this

  

Notice: Undefined index: id in   /opt/lampp/htdocs/curso-php/databases/app/control/admin/usersControl.php   online 21

    
asked by Asdrubal Hernandez 05.07.2018 в 02:22
source

1 answer

1
  • If you use a Framework, the GET method is collected differently. Read the documentation on the official website.

If you use symfony here is what you need: link

If you use Laravel: link

If you want to receive parameters, think that the browser makes a request to the server. That is a request.

  

You can process the requests and print them on the screen with   var_dump ($ request- > query-> gt ('id')); die;
   die completes the script and returns the var_dump to the browser in text.

Anyway, in order to collect the id of a nice url you need to declare it in the Routing and you pass the id by parameter to the function.

//Incluye el paquete que se encarga de las peticiones al principio del controlador
use Symfony\Component\HttpFoundation\Request;

/**
 *
 * @Route("/{id}", name="message")
 * @Method("GET")
 * @Template("ExampleBundle:Message:edit.html.twig")
 */

public function createAction(Request $request, $id){
   $valor = $request->query->get('id');
}

link - If you do not do it with any framework, use var_dump ($ _ GET) to have it returned

    
answered by 05.07.2018 / 10:43
source