Hello everyone.
I'm new here and to php mvc. Been trying to hone my skills with mvc, mysql, classes and functions. But I am stuck. Can display all blog posts from DB but not a single post. The Readmore link only leads to post 1 (or the next published post from the db). Please I need your help. My code is below. Thanx in advance.
BlogsModel.php (PDO db):
public static function getBlog($blogsID) {
try {
$db = static::getDB();
$stmt = $db->query('SELECT *
FROM blogs
WHERE blogsStatus=1 AND blogsID=blogsID
');
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
Blogs.php (Controller):
public function blogAction() {
$blog = BlogsModel::getBlog($blogsID = 'blogsID');
$user = BlogsModel::getBlog($blogsUserID = 'blogsUserID');
$data = [
'blog' => $blog,
'user' => $user
];
View::renderTemplate("Services/Blogs/blog.php", $data);
}
index.php (front controller):
$router->add('blogs/{id:[\w-]+}', ['controller' => 'Services\Blogs', 'action' => 'show']);
ReadMore link:
<a id="readMore" href="/blogs/{{ blog.blogsAlias }}" >ReadMore</a>