Hello,
I think this question may not have a definite answer, but still I'm looking for advice of PHP experts.
I've built a small multi-user PHP application, where users can log in and post some data into it. The app stores the data in MySQL database. It also processes the data in many various ways and shows it to users. Users can browse pages of each other. Also anonymous users can browse some part of the pages (but not all of the functionality is available for them).
That's just a general description, but I hope it's enough to understand the idea.
Since I was new to PHP when I created it, I didn't use object-oriented approach at all, no caching, no optimization, etc. Now I have a definite feeling that I should change the architecture of the whole app.
Currently I have 2 main libraries: "DB Operations" which is used to work with MySQL database, and "UI Operations" which shows everything to user. So each application page is a call of main "UI Operations" functions that outputs everything according to the page/user/request.
The question is: what is the best object model and architecture for it?
What kind of classes it is wise to create in this case?
My own preliminary idea was to create a class User. Then, for example, when user logs in, the app should get all required stuff from DB and store it in the User object, also storing this User object in a session. And then get the required pieces of those data from the object (reading it from the session).
One of the problems now is that all the pages have sidebars which are the same for each page. So there are several identical requests sent to MySQL database on each page, and same results are returned. This is obviously not optimal.
I thought that storing User class in session would solve this problem providing some kind of cache. But I'm not sure.
Perhaps, the main app class should be created to perform same operations as my "DB/UI Operations" do now.
I also looked through MediaWiki engine. I thought that WebRequest class might be useful too. Not sure about it too 🙂
I will highly appreciate any ideas/advice on this subject. Perhaps you may recommend me some other relevant source code to study, it'll be helpful as well.
Thank you.