gpt4 book ai didi

php - 不在对象上下文中时使用 $this

转载 作者:行者123 更新时间:2023-12-02 07:52:28 25 4
gpt4 key购买 nike

我正在创建一个显示博客的功能。所以我制作了一个 show blog 函数,但它一直给出“Using $this when not in object context”错误

Class Blog{

public function getLatestBlogsBig($cat = null){
$sqlString = "SELECT blog_id FROM jab_blog";
if($cat != null)
$sqlString .= " WHERE blog_cat = " . $cat;

$sqlString .= " ORDER BY blog_id DESC LIMIT 5";
$blog = mysql_query($sqlString);

while($id = mysql_result($blog,"blog_id")){
$this->showBlog($id); //Error is on this line
}

}

function showBlog($id,$small = false){
$sqlString = "SELECT blog_id FROM jab_blog WHERE blog_id=" . $id . ";";
$blog = mysql_query($sqlString);

if($small = true){
echo "<ul>";
while($blogItem = mysql_fetch_array($blog)){
echo '<a href="' . $_SESSION['JAB_LINK'] . "blog/" . $blogItem['blog_id'] . "/" . SimpleUrl::toAscii($blogItem['blog_title']) .'">' .
$blogItem['blog_title'] . '</a></li>';
}
echo "</ul>";
}else{
while($blogItem = mysql_fetch_array($blog)){
?>
<div class="post">
<h2 class="title"><a href="<?php echo $_SESSION['JAB_LINK'] . "blog/" . $blogItem['blog_id'] . "/" . SimpleUrl::toAscii($blogItem['blog_title']);?>"><?php echo $blogItem['blog_title'];?></a></h2>
<p class="meta"><span class="date">The date implement</span><span class="posted">Posted by <a href="#">Someone</a></span></p>
<div style="clear: both;">&nbsp;</div>
<div class="entry">
<?php echo $blogItem['blog_content'];?>
</div>
</div>
<?php
}
}
}
}

最佳答案

如何调用 getLatestBlogsBig?如果您在静态上下文中调用它 (Blog::getLatestBlogsBig()),则 $this 无法解析为对象。您需要在 Blog 类的实例上调用 getLatestBlogsBig 方法。

关于php - 不在对象上下文中时使用 $this,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2840695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com