定义一个类以调用其函数,但无法识别并显示错误

时间:2018-06-24 04:29:33

标签: php html oop

1。这是要关注的课程

class Follow extends User {
protected $pdo;

function __construct($pdo){
    $this->pdo = $pdo;
}
public function checkFollow($followerID, $user_id){
    $stmt = $this->pdo->prepare("SELECT * FROM `follow` WHERE `sender` = :user_id AND `receiver` = :followerID ");
    $stmt->bindParam(":user_id", $user_id, PDO::PARAM_INT);
    $stmt->bindParam(":followerID", $followerID, PDO::PARAM_INT);
    $stmt->execute();
    return $stmt->fetch(PDO::FETCH_ASSOC);
}

public function followBtn($profileID, $user_id){
    $data =$this->checkFollow($profileID, $user_id);
    if ($this->loggedIn()===true) {

        if ($profileID != $user_id) {
            if ($data['receiver'] == $profileID) {
                //following btn
                echo "<button class='f-btn following-btn follow-btn' data-follow='".$profileID."'>Following</button>";
            }else{
                //follow btn
                echo "<button class='f-btn following-btn follow-btn' data-follow='".$profileID."'><i class='fa fa-user-plus'></i>Follow</button>";

            }
        }else{
            //edit button
                        echo "<button class='f-btn' onclick=location.href='profileEdit.php'>Edit</button>";

        }
    }else{
        echo "<button class='f-btn' onclick=location.href='index.php'><i class='fa fa-user-plus'></i>Follow</button>";
    }
}

}

2。这是我的html代码,如果用户未登录则调用该按钮

 <body>
   <div class="edit-button">
        <span>
            <?php $getFromF->followBtn($profileId, $user_id); ?>
        </span>
    </div>
  </body>

它显示这些错误 注意:未定义变量:C:\ xampp \ htdocs \ profile.php

中的getFromF

1 个答案:

答案 0 :(得分:0)

这是在告诉您您从未定义$getFromF,并且在您发布的代码中我看不到您这样做。 您需要这样做:

$getFromF = new Follow;

这将实例化您的课程。