bradgrafelman;10954964 wrote:I guess it would depend on your application, but if you had a User class, you'd probably supply some accessors and mutators to set the appropriate data, e.g.
$user = new User();
$user->setUsername($_POST['user']);
$user->setPassword($_POST['pass']);
// etc.
You could even get fancy with it and surround the mutators in a try/catch block so that your User class could throw exceptions if invalid data is passed (e.g. you call setUsername() with a blank username, or setPassword() with a weak password).
Not sure I understand what you mean by that. A class is like a blueprint of what an object can look like and/or do, and a form is just some HTML markup rendered by a browser. I would say that you're comparing apples to oranges, but it's really more like comparing apples to clothespins.
If I had a "registration form", in conventional terms, I would create a file called "registration.php" that would include HTML to create the page and form and PHP to handle the form submission.
If I am now trying to do this using OOP, my question was, "What files would I have?"
I have read that one class should be one .php file.
class Customer ---> customer.class.php
class Order ---> order.class.php
So if I'm taking an OOP approach, would I maybe have...
1.) A file consisting of HTML to display the form...
registration.php (includes HTML)
2.) A file that consists of a class to handle the actual registration...
registration.class.php
3.) A file that consists of a class that represents the Customer and maybe writes the data to the database...
customer.class.php
What I just described was something I used to see more which was called a "3-Tier Architecture" where there was a "Presentation Layer" (i.e. #1) which was the UI, a "Business Layer" (i.e. #2) which contained the business rules/logic/processing, and a "Data Layer" (i.e. #3) which took care of capturing the data and ultimately writing it to the back-end database.
Unfortunately this seems to be different from how the MVC model works?! :queasy:
At any rate, so I thought maybe having:
- registration.php
- registration.class.php
- customer.class.php
would be a good way to do OOP for registering a Customer.
Make sense?!
TomTees