【发布时间】:2018-06-02 06:10:25
【问题描述】:
更新 1:
我忘了添加GetTags()方法,所以这里是:
public $blog_tags;
public function GetTags()
{
return $this->blog_tags;
}
================================================ ============================
我正在使用 PHP OOP 开发我的项目。基本上我有一个名为blogs 的表,其中包含一些字段和数据,如下图:
然后我创建了一个类Blos.class.php,并做了如下两个方法:
public function ShowTag()
{
$tag = $this->_db->prepare("SELECT blog_tags FROM blogs");
$tag->execute();
while($row = $tag->fetch())
{
$this->blog_tags = $row['blog_tags'];
}
}
public function NumTag()
{
$cat = $this->_db->prepare("SELECT blog_tags FROM blogs");
$cat->execute();
$row_cat = $cat->rowCount();
return $row_cat;
}
然后为了在屏幕上检索数据,我这样做了:
$tagSet = new Blogs();
$tags = $tagSet->NumTag();
$tagShow = $tagSet->ShowTag();
if(!empty($tags)){
$tagShow->GetTags();
}else{
echo "There is no tag available right now!";
}
但问题是我收到此错误消息:
致命错误:未捕获的错误:在第 20 行调用 null 上的成员函数 GetTags()
这是哪一行:
$tagShow->GetTags();
那有什么错误呢?你能帮帮我吗?
【问题讨论】: