I have been reading a fair amount about Model-View-Controller (MVC), and am still confused what each is supposed to do. (There doesn't seem to be as much consensus as you'd expect on such a common pattern?!)
I'm trying to build an e-commerce site from scratch, have my website sketched out on paper, and have detailed use-cases.
In order to "get my feet wet" with PHP, OOP, and MVC, I am trying to code just a small portion of the larger site by building the "Customer Registration module".
Here is what I have so far...
Customer table:
- id
- username
- password
- first_name
- last_name
- address
- city
- state
- zip
- tele_no
Registration process: (simplified)
- A "User" can be a "Visitor" or "Customer".
- A "Visitor" decides to Register and become a "Customer"
- The System asks for a Username (E-mail), Password, and AcceptTermsYN.
- The User enters a Username, Password, and Accepts the Terms.
- The System ensures the Username is unique.
- The System ensures Usernames match.
- The System ensures the Passwords match.
- The System ensures the User accepted the "Terms".
- The System creates a new Customer Account (record).
- The System sends an "Activation E-mail" to the User's E-mail.
- The User clicks on a link in the e-mail.
- The System confirms the e-mail is valid (i.e. receives response back)
- The System activates the Customer's Account.
- The "Visitor" is now a registered "Customer".
Customer class:
(same as "Customer" table)
Registration class:
Properties:
- username
- password
- accept_terms
Methods:
- checkUsernameUnique()
- checkUsernameValid()
- checkPasswordValid()
- checkAcceptTerms()
- createCustomerAccount()
- sendActivationEmail()
- activateCustomerAccount()
Comments:
Registration only requires working with Username, Password, and AcceptTermsYN. It is not until "Checkout" that the additional fields in the Customer class/table are needed.
I have been told that...
class Customer == Model
class Registration == Controller
form Registration == View
This is what I have found online for definitions of each...
MODEL:
- "Represents enterprise data and the business rules that govern access to and updates of this data."
"Often serves as a software approximation to a real-world process."
"The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller)."
CONTROLLER:
- "A Controller accepts input from the user and instructs the Model and Viewport to perform actions based on that input."
"The Controller receives GET or POST input and decides what to do with it, handing over to domain objects (i.e. the Model)"
"The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate."
This leads me to believe that...
class Registration (and maybe class Customer) == Model
??? == Controller
form Registration == View
QUESTIONS:
1.) What is the Controller in my example above?
2.) What is the Model in my example above?
3.) Does my design look okay so far?
(I do believe that "Registration" needs to be its own class since it is a process/service that is logically separate from a "Customer".)
TomTees