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.
model.php connects to the database and retrieves the post. view.php will just display the post.
model.php
<?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);
?>
view.php
<?php
require "model.php";
echo $post;
?>
I set my browser location to http://whateverhost/view.php?id=5
This loads post with the id 5. I did not require a controller here. So I am confused why do you need a controller?
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.
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.