Receive data from database and pass to html using twig

This commit is contained in:
2017-09-04 16:20:27 +07:00
parent aa60edbbf0
commit e1d70ed8f4
6 changed files with 57 additions and 32 deletions

View File

@@ -41,10 +41,8 @@ class Post extends \Core\Model
if ($stmt = $db->query($sql)) {
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
// For tests
return true;
return $result;
}
return false;
} catch (PDOException $e) {
echo $e->getMessage();
}
@@ -62,11 +60,29 @@ class Post extends \Core\Model
if ($query->execute([$id])) {
if ($query->rowCount() === 1) {
$result = $query->fetchAll(\PDO::FETCH_ASSOC);
// For tests
return true;
return $result;
}
}
} catch (PDOException $e) {
echo $e->getMessage();
}
}
public function showCategories()
{
try {
$db = static::connectDB();
$sql = "SELECT * FROM kategori";
$query = $db->prepare($sql);
if ($query->execute()) {
if ($query->rowCount() > 1) {
$results = $query->fetchAll(\PDO::FETCH_ASSOC);
return $results;
}
}
return false;
} catch (PDOException $e) {
echo $e->getMessage();
}