Receive data from database and pass to html using twig
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user