I'm trying to apply a simple MVC pattern to my current website without any frameworks. Since i haven't really gotten into oop yet im still using procedural at the moment.
I have a simple login form (view)
<formaction="controller/login.php"method="Post"><inputtype="text"name="username"placeholder="Username"/><inputtype="text"name="password"placeholder="Password"/><inputtype="submit"value="Sign in"/></form>
this form will submit to the controller for login form. Controller will now check if both fields have inputs and "cleanse" more or less the input
if(isset($_POST['username'])){ $username = $_POST['username']; $password = $_POST['password']; $username_escape = mysqli_real_escape_string($connect, $username); $password_escape = mysqli_real_escape_string($connect, $password);} header("../model/login.php");
this is a really simple check right now however i was now wondering should i include controller into model and redirect to model from controller or form submit it at first place and have controller included.
Model
include_once("../controller/login.php"); $query = mysqli_query($connect,"INSERT into DB_table (username, password) VALUES($username_escape, $password_escape)");
Allen Scott
10-Nov-2014It's good that you're trying to separate your concerns, but MVC is a design pattern based on top of OOP principles.
OOP works with objects, and those objects are defined by a class, which is like a blueprint.
So in this example, you'd want everything to go through the controller, then depending on whether you want to save out, you'd want to call the model.
eg.
As you can see the logic is separated into a service, and is only called if it is needed. We've also used pdo to prevent SQL injections, (though shouldn't really be creating objects in here).
Id suggest you look into autoloading, and have a play with a framework like Silex as it will teach you these principles.