W
W
wertex2017-08-15 21:58:27
Yii
wertex, 2017-08-15 21:58:27

Is it better to create a class or is it enough to use a model?

There are employees. It is necessary to make a small service for generating applications for an ES certificate.
The application includes the following information: full name, snils, tax number, passport details, department and position.
At the moment I am reading a book on OOP (Weisfeld M. - Object-Oriented Thinking). The author suggests using classes, inheritance and all other OOP features.
Is it necessary to create, for example, a Passport class inside which to "carry out" various data manipulations: for example, they filled in the fields for the passport (number, date, who issued it) sent via POST to the controller, which, in turn, went to Class Passport, which checked them and sent them to the model for saving... or then the model is not needed? Or here you can immediately send it from the controller to the model and validate it there and save it to the database, and Class Passport is not needed at all.
And if you do it through OOP, then create classes / abstract / interfaces / and so on?
employee->passport
->inn
->snils I'm
trying to do a service on yii2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Night, 2017-08-15
@maxtm

You have a little mess in your head :)
If you want to do everything according to the "true" OOP - then do it, all entities - objects, SOLID principles, etc.
Make a service (a separate class) that is responsible for validating, creating, editing the entities you need, and give all the logic to it.
What he will operate with, the Passport class, the model is not the point. The main thing is that it should be one entry / exit point, which has a simple API.

I
ipokos, 2017-08-15
@ipokos

If this is a "live" project, I advise you to start with some kind of educational, simpler ones, because. it may turn out that you will use only syntax from OOP and porridge from MVC.
The purpose of MVC is to separate the responsibilities of code.
For example, a separate class for data validation (in it you check the data type, clear possible tags, etc., check for the correctness of the data and it is better to do this in separate methods)
A separate class (controller) for working with already prepared data
A separate class (model ) to work with the entity (make a selection from the database, write to the database)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question