1
Good afternoon to everyone, before explaining a little more about the doubt I would like to make it clear that I am very lay in the subject and, amazingly, I’ve been trying to solve this problem for weeks. Doubt: I would like to list some data from my BD, in case the user would enter a date and the system would list only records containing that date, as if it were a filter. After several tests I only managed to make a simple list, without any filter, follows the codes:(home.ts)
carregarProdutos(){
this.produtoProvider.getAll()
.then(data => {
this.produtos = data;
});
}
products.ts(Preview)
getAll() {
return new Promise(resolve => {
this.http.get(this.URL+'/produto').subscribe(data => {
resolve(data);
}, err => {
console.log(err);
});
});
}
Index.php
$app->get('/produto/', function() use ($app){
(new \controllers\Produto($app))->lista();
});
Controller product.php
public function lista(){
global $app;
$sth = $this->PDO->prepare("SELECT * FROM produtos");
$sth->execute();
$result = $sth->fetchAll(\PDO::FETCH_ASSOC);
$app->render('default.php',["data"=>$result],200);
}
As I said this code is working, but I can not in any way make the variable transport so that it stays like this:
$sth = $this->PDO->prepare("SELECT * FROM produtos WHERE data= :data");
$sth ->bindValue(':data',$data);
Again I’m sorry, but I’m really layabout.
What framework is sweating in PHP.
– Jorge Costa
Restful API with PHP Slim Framework, that would be it?
– Lucas Vilela
Follow git: https://github.com/ClubeDosGeeksCoding/api-php-slim-framework
– Lucas Vilela