我希望你能帮我解决这个问题:
我尝试在php + HTML5 + css中实现模式MVC。现在,除了模型之外,当我尝试在我的一个Controller中实例化PHP对象时,我遇到了问题。
特别是,我必须打印有关经过身份验证的用户的数据,该数据存储在一个对象$ userObject中,我尝试使用DataBase数据进行实例化。
所以我声明了,我在Null初始化它,然后,我尝试用他的构造函数实例化它。
之后,当我尝试使用它时,PHP告诉我:“在C:\ Users \ 1USER \ Documents \ EasyPHP-DevServer中的非对象上调用成员函数getEmail()第99行的-14.1VC11 \ data \ localweb \ projects \ ammPHP \ PHP \ Controller \ LoginController.php“
我向您展示有关问题的代码摘录:
/**the function handle_input rappresent the core of my controller, that popolates the variables of the master.PHP to make a virtual page and to visualize the user's profile.**/
private function handle_input(&$request, &$session)
{
$userObject = null;
$mysqli = new mysqli();
//login module: it verify the user data and modify the $_SESSION's array
//It makes also an object of class AuthenticatedUser that full with the database Data about the logged user.
if(isset($request["userid"]) && isset($request["password"]))
{
if($this->login($request["userid"], $request["password"]))
{
$session["loggedIn"] = true;
$mysqli->connect("localhost", "root", "password", "database");
$userid = $request["userid"];
$password = $request["password"];
$query = "SELECT * FROM loggeduser WHERE (userID = '$userid') AND (passwd = '$password');";
$result = $mysqli->query($query);
//errors checking salted
while($user = $result->fetch_object())
{
$userObject = new AuthenticatedUser($userid, $password, $user -> email, $user -> nome, $user -> cognome, $user -> dataNascita, $user -> città, $user -> CAP, $user -> indirizzo, $user -> cellulare);
}
}//user is logged-in
else if(isset($request["logout"]))
{
$this->logout();
}
//Master.php dedicated module: It verify that user is logged-in, then initialize
//the variables to popolate the master PHP and to make the virtual page of the profile's user.
if(isset($_SESSION["loggedIn"]) && $_SESSION[ "loggedIn"])
{
//CONTROLLO SULLE PAGINA RICHIESTE
if ($request["subpage"] == "profile")
{
$style = "PHP/view/LoggedUserStyle.php";
$header = "PHP/view/Header.php";
$loginFormContent = "PHP/view/loggedUserMenu.php"; //modificato col menù per utenti autenticati
$slideshow = null;
$userProfile = "PHP/view/userProfile.php";
**$user = $userObject -> getEmail(); //Here the problem, PHP tells me that $userObject is not an object! :/**
$payments = null;
$orders = null;
$notFoundContent ="PHP/view/content-not-found.php";
$footer="PHP/view/footer.php";
include("master.php");
}
[...]
}//closing function handle_input