感谢上一个问题的帮助 我在Topic类中的项目有问题,可以查看特殊类别中的所有主题 在主题'中查看我的功能。类:
/*
* 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;
?>
当我点击类别链接(&#39; topics.php?category = 1&#39;)时出现此错误:
注意:未定义的变量:他的 第74行的C:\ xampp \ htdocs \ talkingspace \ libraries \ Topic.php
注意:尝试获取非对象的属性 第74行的C:\ xampp \ htdocs \ talkingspace \ libraries \ Topic.php
致命错误:在null中调用成员函数bind() 第74行的C:\ xampp \ htdocs \ talkingspace \ libraries \ Topic.php
我想也许我在DB的SELECT for SELECT中失败了。
任何帮助的最佳问候。
答案 0 :(得分:2)
纠正这一行
$his->db->bind(':category_id', $category_id);
$this
而不是$his
$this->db->bind(':category_id', $category_id);
答案 1 :(得分:2)
在主题类的$his
函数中将$this
修改为getByCategory()
。