Jump to content

sidekick

New Members
  • Posts

    4
  • Joined

  • Last visited

sidekick's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @Strider64 Your input looks interesting and I will definitely look into it
  2. Hi guys Been busy with another project but am back to look further into this. Here is the current code as requested by NotionCommotion. BlogsModel.php public static function getBlog($id) { try { $db = static::getDBUserContent(); $stmt = $db->prepare('SELECT * FROM blogs WHERE blogsStatus=1 AND id=:id '); $stmt->bindValue(':id', $id, PDO::PARAM_INT); $stmt->execute([':id' => $id]); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result; Blogs.php (controller) public function blogAction() { $blog = BlogsModel::getBlog($id = 'id'); $data = [ 'blog' => $blog, 'user' => $user ]; Index.php (front controller) $router->add('blogs/{id:[\w-]+}', ['controller' => 'Services\Blogs', 'action' => 'blog']); Thanx again
  3. Hi NotionCommotion and Barand Thank you very much for your speedy and helpful replies. I made changes as requested above, however, I had to change 'query' to 'prepare' as it threw an error. I tried both above and they both gave me a blank page. I did a var_dump() on the routes and this is what I get: array(1) { ["blogs/test-blog-4"]=> string(0) "" } array(23) { ["/^(?P[a-z-]+)\/(?P[a-z-]+)$/i"]=> array(0) { } ["/^blogs\/(?P[\w-]+)$/i"]=> array(2) { ["controller"]=> string(14) "Services\Blogs" ["action"]=> string(4) "blog" } I had clicked on the ReadMore link for Test Blog 4. The slug of the blog post is correct in the url but nothing shows. Thanx again
  4. 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>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.