Answer the question
In order to leave comments, you need to log in
How to organize logic in a single page PHP application?
Hello.
I have a single page application in php. There are tabs on the page, in each tab there is a form responsible for a certain functionality.
There are a lot of if'ov, checking what form is submitted:
If form_1, then do it.
If form_2, then this.
How many tabs, so many such blocks, and inside them the fullness of certain fields is checked (often they are duplicated). Those. the main php file of the application has turned into a big footcloth of such ifs.
How to organize the logic so that there is no duplication of checks and ensure the scalability of the application? And tell me the literature on designing web applications.
Answer the question
In order to leave comments, you need to log in
The most correct option is to use OOP. We need a set of classes.
1. A class for validating form fields
2. One class for processing each form (moreover, we move the common methods for all forms to the base class and the rest inherit it)
3. A factory class that will return the form object we need to work with
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question