Integration: MySocial
      Introduction
Interdisciplinary Web Development
              CGS2835
Model-View-Controller
• Model: Code to process, retrieve, and store data on a server (PHP,
   MySQL)
• View: Renders the Model into a website (XHTML, CSS)
• Controller: Processes user input (JavaScript, PHP, XHTML)




                              CGS2835 WebDev
Model-View-Controller

User input (click a link, submit a form)

                                                PHP/JavaScript
                                                                      Adds/Removes data from the Database

                              Shows a webpage


                                    Updates information to the webpage


              What you see                                                          Database
                                    Requests Data from the database




                                           http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

                                                CGS2835 WebDev
Model
• MySQL Database
  – Tables and Fields to store data
• What kind of information would you need to
  store for a social net?




                       CGS2835 WebDev
Model
• TABLE: users
  – userID, username, password, picture
• TABLE: posts
  – userID, post, time
• TABLE: friends
  – user, friend




                         CGS2835 WebDev
Model
• database_queries.php
  – MySQL queries to put and get data
  – Handles all database access
• connect.php
  – Connection functions in one place
• security.php
  – Functions for sanitization of input
  – Functions for password hashing
  – Functions for user authentication
                       CGS2835 WebDev
View
• What things do all pages need to see?
• top.php
  – The top navigation bar of all pages
  – Specifies the style sheet to be used “style.css”
  – Included on all view pages with
     • <?php include(“top.php”); ?>




                        CGS2835 WebDev
View
• index.php: Main page
• user.php?userID=
  – Choosing a user profile to show using $_GET
  – $_GET is like $_POST except it gets information after
    the ? in the address instead of a form that posts
    information
  – Shows a user’s page, their posts and information
  – Shows a form to make a post on a user page
• user_form.php
  – Shows the forms for making a new user and logging in

                        CGS2835 WebDev
Controller
• Handles $_POST from forms and sends the
  data to database_queries.php functions
• newuser_process.php
  – Processes the new user form
• user_process.php
  – Processes the user login form
• post_process.php
  – Processes the user post form

                      CGS2835 WebDev

Mysocial

  • 1.
    Integration: MySocial Introduction Interdisciplinary Web Development CGS2835
  • 2.
    Model-View-Controller • Model: Codeto process, retrieve, and store data on a server (PHP, MySQL) • View: Renders the Model into a website (XHTML, CSS) • Controller: Processes user input (JavaScript, PHP, XHTML) CGS2835 WebDev
  • 3.
    Model-View-Controller User input (clicka link, submit a form) PHP/JavaScript Adds/Removes data from the Database Shows a webpage Updates information to the webpage What you see Database Requests Data from the database http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller CGS2835 WebDev
  • 4.
    Model • MySQL Database – Tables and Fields to store data • What kind of information would you need to store for a social net? CGS2835 WebDev
  • 5.
    Model • TABLE: users – userID, username, password, picture • TABLE: posts – userID, post, time • TABLE: friends – user, friend CGS2835 WebDev
  • 6.
    Model • database_queries.php – MySQL queries to put and get data – Handles all database access • connect.php – Connection functions in one place • security.php – Functions for sanitization of input – Functions for password hashing – Functions for user authentication CGS2835 WebDev
  • 7.
    View • What thingsdo all pages need to see? • top.php – The top navigation bar of all pages – Specifies the style sheet to be used “style.css” – Included on all view pages with • <?php include(“top.php”); ?> CGS2835 WebDev
  • 8.
    View • index.php: Mainpage • user.php?userID= – Choosing a user profile to show using $_GET – $_GET is like $_POST except it gets information after the ? in the address instead of a form that posts information – Shows a user’s page, their posts and information – Shows a form to make a post on a user page • user_form.php – Shows the forms for making a new user and logging in CGS2835 WebDev
  • 9.
    Controller • Handles $_POSTfrom forms and sends the data to database_queries.php functions • newuser_process.php – Processes the new user form • user_process.php – Processes the user login form • post_process.php – Processes the user post form CGS2835 WebDev