O
O
Orbb2016-06-27 22:30:59
PHP
Orbb, 2016-06-27 22:30:59

How to design classes?

Good day!
Rewriting my small project from scratch using classes.
Tell me, experienced colleagues.
There is such a code:
f61eced4f5f64c93bf73bf9aead14bc5.PNG
it displays such a thing (everything is scattered, it doesn’t matter where which column is)
27b8db5c03b24dfd936f1412e6fab89a.PNG
Now the question is:
0fce09c21ea04ac7b301af04b2c1ead9.PNG
I want to rewrite the same code in OOP, or maybe even switch to it from the procedural.
Obviously, there will be a bunch of scripts, they all need to be transferred according to the OOP methodology. In OOP, I understand and use a little - I understand how abstract classes, static methods, traits, interfaces work, but how and where to apply, and most importantly why - no.
Tell me, according to what logic to display information from classes, - to make a method inside a class or a separate class that will only edit, according to what principle then to enter this information into the database - again a class or embed a method in a class? Where to use static methods, where are traits better? And do I need them here at all?
How would you design?
The functions are mainly output of information to the template, adding information to the database, sorting, updating.
I would love to use the twig, but then my code will be very complicated for me and it's good if I finish the project in a year or two.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
novrm, 2016-06-27
@novrm

If the first is outputting information to a template, definitely go to twig.
When you start using twig, you will be pleasantly surprised how easy the entry threshold is...
For database work, try Doctrine 2 Object Relational Mapper (ORM) .
If you saw something of your own - use Object Relational Mapping.
If you want everything at once and more: twig, ORM, OOP all in one - take some kind of framework - for example, Zend Framework or Symfony.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question