title: What is the job of controller in MVC?
body: <p>I am trying to learn the MVC architecture. But I am not able to understand why you need a controller. See the below code for my model and view.</p>
  
  <p>model.php connects to the database and retrieves the post. view.php will just display the post. </p>
  
  <p>model.php</p>
  
  <pre><code>&lt;?php
    $db = mysql_connect("somehostname", "someuser", constant("somepassword"));
    mysql_select_db("somedatabase", $db);
  
    $result = mysql_query("SELECT post FROM posts WHERE postid='" . $_POST['id'] . "'");
    $row = mysql_fetch_array($result);
  
    $post = $row["post"];
  
    mysql_close($db);
  ?&gt;
  </code></pre>
  
  <p>view.php</p>
  
  <pre><code>&lt;?php
    require "model.php";
    echo $post;
  ?&gt;
  </code></pre>
  
  <p>I set my browser location to <a href="http://whateverhost/view.php?id=5" rel="noreferrer">http://whateverhost/view.php?id=5</a></p>
  
  <p>This loads post with the id 5. I did not require a controller here. So I am confused why do you need a controller?</p>
  
  <p>Note: Please explain with reference to the above example. I am not a programming geek and learning things like CakePHP, etc. is overwhelming for me.</p>
  
  <p>Edit: It would be great if you can add controller.php to the above code. That would help me in understanding the role of a controller and how it communicates with model and views.</p>