Ask HN: how to Learn MVC?

1 points by shire ↗ HN
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.

6 comments

[ 3.4 ms ] story [ 14.7 ms ] thread
Check out this Rails MVC pattern (http://addyosmani.github.io/backbone-fundamentals/#mvc-appli...) explained by Addy Osmani for developing Backbone Apps. Rails MVC is said to be very similar to Django MVC, so this should be pretty useful.
I'm not really sure that that book is good for Django MVC or even rails since Backbone MVC is a little different and some consider it to be a MV*.
Don't read the whole book. Just the Rails MVC pattern section I linked you.
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.
feel free to contact me muhammedcode@gmail.com
a primer on mvc

ill just give a easy to understand (?) example

MVC Model View Controller

    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>
Now you understand MVC! =)