How do I measure parameters of my view to the model where the method is located, which occupies the parameter?

0

What happens is that I only pass a parameter from my view to the model where the method is for example:

* VIEW:

<h1>    <?php foreach($this->modelo->Listar(2) as $r):?>
        <?php echo $r->contenido ;?>
        <?php endforeach;?>
</h1>

"List" is the name of my method that is in the model

* MODEL:

public function Listar($id){
    try{


        $query = $this->v->prepare("SELECT * FROM parrafo WHERE id_parrafo=?");
        $query->execute(array($id));        
        return $query->fetch(PDO::FETCH_OBJ);

    }catch(Exception $e){
die($e->getMessage());
    }
}

I want to pass the parameter of the view to the model and it is assigned in the following of "?"

I hope to give you to understand is my first question on this site.

    
asked by Bruno 17.07.2018 в 01:24
source

1 answer

0

must send the parameter to the sentence prepared example.

public function Listar($id){
    try{


     $query = $this->v->prepare("SELECT * FROM parrafo WHERE id_parrafo=?");
     $sentencia->bindParam("s", $id);
     $query->execute($query);        

     return $query->fetch(PDO::FETCH_OBJ);

   }catch(Exception $e){
     die($e->getMessage());
   }
}
    
answered by 17.07.2018 в 03:08