I'm learning Python and Django but I need to grasp this MVC pattern stuff. Any good books or screencasts explaining how MVC works? I'm a beginner so a basic explanation would be appreciated.
Would be great to talk to you more, based on your previous questions/posts, but no contact info listed. I have some of the same questions that you've had.
Model: this is a data model [access pattern]
models/users.code:
class User {
function getUsers() {
$db->fetchAll("SELECT * FROM USERS LEFT JOIN CRAZYTABLE ON CRAZYSTUFf = 1")
}
}
Controller: Handles application logic
controllers/userlist.code
requires('models/user.code')
function showUsers() {
$users = User::getUsers()
$usernames = []
foreach($users as $row)
$usernames[] = $row['name']
renderView('views/userpage.html', $usernames)
return
}
View: Display logic, ideally as simple as possible
Could be a html template or a windows form
Purists say you should do all data validation and preperation in the controller
views/userpage.html
<div id=myuserlist>
<h1>Our users</h1>
<ul>
{{ foreach $users as $user }}
<li>{{ $user }}</li>
{{ endforeach }}
</ul>
</div>
6 comments
[ 3.4 ms ] story [ 14.7 ms ] threadill just give a easy to understand (?) example
MVC Model View Controller
Now you understand MVC! =)