从类到php页面打印变量

时间:2015-12-22 18:59:59

标签: php

我不知道如何将类中的变量返回到另一个php页面。

在这里,我填写课程并将其放入会话中:

$query = "SELECT * FROM gebruiker";

$result = mysqli_query($link, $query) or die("Er is een fout opgetreden bij het uitvoeren van de query: \"$query\"");

while($rij = mysqli_fetch_array($result))
{
    if ($rij['ID'] == $_SESSION['user'])
    {
        $naam = $rij['Naam'];

        include_once("class/Gebruikers.php");
        include_once("class/Admin.php");

        //class invullen
        $admin1 = new Admin($rij['ID'], $rij['Naam'], $rij['E-mail'], $rij['Rechten']);
        $_SESSION['admin'] = $admin1;

    }       
}

这是我的班级文件:     

class Admin extends Gebruiker
{
    private $m_rechten;

    public function printen($recht)
    {
         $rechten = $this->m_rechten
         return $rechten;
    }

    public function __toString() 
    {

        return $this->m_rechten;
    }

    public function __construct($p_ID="", $p_naam="",$p_email="",$p_rechten="")
    {
        parent::__construct($p_ID, $p_naam,$p_email);

            $this->m_rechten=$p_rechten;
    }
}
?>

这是我要打印课程结果的另一页。     

    session_start();

    //check to make sure the session variable is registered

    $result = $_SESSION['admin']->printen($recht);

    print $result;
?>

我的错误是

  

解析错误:语法错误,意外'返回'第12行的C:\ Users \ vincent \ Documents \ XAMPP \ htdocs \ PHP \ Project \ class \ Admin.php中的(T_RETURN)

1 个答案:

答案 0 :(得分:2)

您需要添加;

public function printen($recht)
{
     $this->m_rechten = $recht; // <-- HERE the ; | Use the $recth variable, not $recthen
     return $this->m_rechten;
}