I started building a website, and quickly found out that my code was a mess. Some time has passed since I programmed in PHP, and since then I have learned OOP. Now that a C # or java application is pretty easy from this point of view, PHP is giving me problems.
I used for programming everything (in php) from only one line to another, with a minimal number of methods and without classes at all. So, how much should be in methods and where should these classes be?
Example: I have account.php and I want to update user information. So, after checking that someone sent some data if(isset($_POST[.. , what next? Before, I just did all the checks like $email=CheckForRisksOrSomething($_POST["email]); and then just upgrade mysql.
This brings me to the question: create a User class and what methods should it contain? Also WHERE should save this class, assuming user.php will show you the user profile.
Let's get back to how much class should be, I should just use in the file, for example:
$smth = new Someclass(); if($smth->checkIfSaved()){ $user = new User(); $user->updateUser(); } else { $smth->showUserDetailsForm(); }
Should you also keep Someclass?
So, if ayone gave me an example of how to structure the following functions (in files, classes, and possibly methods).
- users (registration, login, registration) ..
- image with comments
- news (also with comments)
- Administration
This, of course, is an example, but I do not want to continue my mess, and then I will look at it three days later and just look at what I wrote there. Well, I already did it today, which is why I ask.
EDIT 24.2.2016
Although this is an old question, it was supposed to take a look at the structure. Although it may take a little to configure it, it increases the development speed, the code is nice and clean, and much safer. I personally use Laravel.