按类别id获取

get by category id

感谢您对我最后一个问题的帮助 我在主题 class 中的项目有问题,无法查看特殊类别中的所有主题 在 'Topic' class:

中查看我的函数
/*
 * Get topics by Category
 */
public function getByCategory($category_id){
    $this->db->query("SELECT topics.*, categories.*, users.username, users.avatar FROM topics
                        INNER JOIN categories
                        ON topics.category_id = categories.id
                        INNER JOIN users
                        ON topics.user_id = users.id
                        WHERE topics.category_id = :category_id
    ");
    $his->db->bind(':category_id', $category_id);

    //Assign Result Set
    $results = $this->db->resultset();

    return $results;

}

这是我在根文件夹中的 topics.php

<?php   require('core/init.php');?>
<?php
//create New Topic
$topic = new Topic;

//Get Category From URL
$category = isset($_GET['category']) ? $_GET['category'] : null;

//Get user From URL
$user_id = isset($_GET['user']) ? $_GET['user'] : null;

//Get Template & Assign Vars
$template = new Template('templates/topics.php');

//Assign Template Variables
if(isset($category)){
    $template->topics = $topic->getByCategory($category);
    $template->title = 'Posts In "'.$topic->getByCategory($category)->name.'"';
}

//Assign Template Variables
if(isset($user_id)){
    $template->topics = $topic->getByUser($user_id);
    $template->title = 'Posts By "'.$topic->getUser($user_id)->username.'"';
}


if(!isset($category) && !isset($user_id)){
    $template->topics = $topic->getAllTopics();
}

//Assign vars

$template->totalTopics = $topic->getTotalTopics();
$template->totalCategories = $topic->getTotalCategories();

// display Template
echo $template;

?>

当我单击类别 link ('topics.php?category=1') 时出现此错误:

Notice: Undefined variable: his in C:\xampp\htdocs\talkingspace\libraries\Topic.php on line 74

Notice: Trying to get property of non-object in C:\xampp\htdocs\talkingspace\libraries\Topic.php on line 74

Fatal error: Call to a member function bind() on null in C:\xampp\htdocs\talkingspace\libraries\Topic.php on line 74

我想我可能在从数据库查询 SELECT 时失败了。

最好的问候任何帮助。

更正此行

$his->db->bind(':category_id', $category_id);

应该是$this而不是$his

$this->db->bind(':category_id', $category_id);

将主题 Class 的 getByCategory() 函数中的 $his 修改为 $this