Note that there are some explanatory texts on larger screens.

plurals
  1. POquestions about MVC architecture in web application
    primarykey
    data
    text
    <p>I have certain questions since I'm doing a web app, and I feel kinda confused about keeping the mvc structure in a web application without using any frameworks.</p> <p>Here is the structure of my app.</p> <p>index:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;!--&lt;link rel="stylesheet" type="text/css" href="index.css" /&gt;--&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"&gt;&lt;/script&gt; &lt;script src="js/functions.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function() { loginSend(); }); &lt;/script&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="login"&gt; Username: &lt;input type="text" id="username" name="username"&gt;&lt;br&gt; Password: &lt;input type="password" id="password" name="password"&gt;&lt;br&gt; &lt;input id="send" type="button" value="Enviar"&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The loginsend function sends the data to service.php </p> <pre><code>&lt;?php include('server/main.php'); $action = $_POST['action']; switch($action){ case "loginCheck": $username=$_POST['username']; $password=$_POST['password']; $users = new users(); echo $users-&gt;loginCheck($username,$password); break; } ?&gt; </code></pre> <p>And the service uses some classes I defined in main.php</p> <pre><code>&lt;?php class db{ public function conn() { try{ $dbhost = "localhost"; $dbname = "eout"; $dbuser = "root"; $dbpass = ""; if($conn = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass)){ return($conn); } } catch (Exception $e){ echo "Se ha presentado un error al conectar con la base de datos".$e; } } } class users{ function loginCheck($username, $password) { try{ $db = new db(); $conn = $db-&gt;conn(); $pass_encriptada = md5 ($password); $SQL_LOGIN_CHECK = "SELECT * FROM users where username='".$username."' and password='".$pass_encriptada."' and deleted='0'"; $conn-&gt;prepare($SQL_LOGIN_CHECK); foreach($check = $conn-&gt;query($SQL_LOGIN_CHECK) as $row) { $username_check = $row['username']; if ($username_check == $username){ session_start(); $_SESSION['logged'] = 1; $_SESSION['user_id'] = $row['id']; $_SESSION['username'] = $row['username']; $_SESSION['namelastname'] = $row['name'] ." ".$row['lastname']; $usertype_id = $row['usertype_id']; if ($usertype_id == 1 ){ //problema $_SESSION['teacher'] = 1; $response = "teacher"; $json = json_encode($response); echo $json; } if ($usertype_id != 1 ){ //problema $response = "user"; $json = json_encode($response); echo $json; } } } } catch(Exception $e){ echo "Se ha presentado un error en loginCheck".$e; } } } ?&gt; </code></pre> <p>In this case, I understand that index.php its my view, however I have certain doubts about the model/controller part. I understand in my example that the main file is the one that interacts with data, so it must be the model... in my case... its service.php my controller? Since is the one that interacts with the model? I feel kinda confused about this. In case I am wrong. How can I make a controller?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload