Hello everyone.
I am trying to make a simple to-do list program using PHP and the MVC pattern. I have managed to make the login page, the model and the controller for managing logins. It is working properly because it can discern if the user exists or not. After validating the user, it includes another page using require_once(). The problem is that it is displaying the contents of the new page (the one you see after loggin in) right below the login form instead of simply replacing the whole page with the new one. Here is the code. It is located in the index.php page:
<?php
include 'model/user_model.php';
include 'controller/user_controller.php';
include 'view/user_view.php';
$usermodel = new UserModel();
$usercontroller = new UserController($usermodel);
$userview = new UserView($usercontroller, $usermodel);
if(!isset($_SESSION)) {
$userview->outputlogin();
}
if(isset($_REQUEST['name'],$_REQUEST['password'])) {
if ($usercontroller->validateuser($_REQUEST['name'],$_REQUEST['password'])) {
$userview->outputlogged();
}else {
$userview->outputlogin();
echo "<p>Wrong user or password</p>";
}
}
?>
the outputlogged() function does this:
public function outputlogged() {
require_once($this->usermodel->template['logged']);
}
}
It simply outputs the logged.php page which currently only says "You logged in". The problem is that the message is appearing BELOW the login form instead of simply replacing the whole page with the one with the message. What am I doing wrong?