I've been reading and learning about OOP and MVC for the last week or so I would like to know if I'm on the right track.
Here is an example of what I currently have:
index.php Parses the URL that is passed in from Apache mod_rewrite (.htaccess). In this file I also first include my site specific settings and defined variables, then I include the related controller file and then the view.
<?php
// Include the site specific settings
require 'includes/settings.php';
// Include the HTML page header
require LIBPATH . 'views/page_header.php';
//Code to parse the url passed in from mod_rewrite
require LIBPATH . 'controllers/' . $require_url . '.inc.php';
require LIBPATH . 'views/' . $require_url . '.php';
// Include the HTML page footer
require PUBLICPATH . 'includes/page_footer.php';
?>
Moving on to the controller: In this file I make sure that the form $_POST is set and then invoke the model (class).
<?php
if (isset($_POST)) {
$loginUser = new User();
$loginUser->email = $_POST['email'];
$loginUser->password = $_POST['password'];
$returnArray = (json_decode($loginUser->select(), true));
$_SESSION['userID'] = $loginUser->userID;
$_SESSION['firstName'] = $loginUser->firstName;
$_SESSION['lastName'] = $loginUser->lastName;
$_SESSION['email'] = $loginUser->email;
// Redirect code to admin area of the site
}
?>
Now the model (class) code:
<?php
// Basically I'm interacting with the database and returning the data in a JSON encoded array. This is always where I check to make sure that values are set and correct before doing the database queries.
?>
Is this a correct way of using MVC and PHP OOP?
Thank you for your input.