P
P
Programmir2018-02-01 12:55:16
Yii
Programmir, 2018-02-01 12:55:16

Do you need a model in yii2 in this case?

They gave a test task for yii2. So far, everything seems to be clear, since I studied Laravel before. But I don't want to use Active Record, for example. It seems to me that it is easier to write native SQL queries using PDO. It turns out that in this case I do not need a model? And can they not hire me if I say that it is more convenient for me through SQL queries, since Active Record can get confused?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Kim, 2018-02-01
@kimono

I don’t think that you will be hired as a Yii2 programmer if you use your own classes with direct requests via PDO everywhere instead of native AR models (why?).
It's like replacing the computerized steering wheel on an F-1 with a ship's steering wheel and waiting to be allowed to compete.

A
Artem, 2018-02-01
@proudmore

If you refuse AR and models, then you will either validate the data yourself or not at all. Plus, I don't quite understand how you can get confused in AR. One object - one line in the table.
If someone told me at the interview that they would work through PDO, they would immediately go further in search of a job.

M
Maxim Timofeev, 2018-02-01
@webinar

It turns out that in this case I do not need a model?

The model is an integral part of the MCV. If they ask to do it in yii, then they expect the presence of MCV.
Your right, you can put yii in general, and write everything next to it without using it. I have seen many such projects. But if this is your project. And if there is a customer and he requires yii, then he probably expects to see AR. So the question is not at the address, you ask the customer. Especially if it's a test. This is where your knowledge of yii is tested. So in this case, I think AR is definitely to be used. As well as other methods and objects of the framework.
The only argument against AR is performance. The rest, especially "you can get confused" - this is a good reason not to take you. Since it is made for simplicity and readability of the code. And confusion can only be because of his ignorance.
We must first study AR, and then abandon it if necessary. But for a test task, if you want to show the knowledge of pdo, then it is better to implement both and show the difference. This will be a plus. If you do it without AR, because you don't know him, the employer's answer will be obvious.

M
Maxim Fedorov, 2018-02-01
@Maksclub

Let me explain popularly:
For normal use - AR is enough, if you need to make complex selections or you start clearing your models, you can always go down below and file your query through DAO (this is also PDO, but with a more convenient interface)
In order not to spoil, I suggest read manuals from Yii2 team:
I want to note that Active Record is considered the easiest to learn, in fact, in the world of web development, Active Record and Data Mapper (Doctrine) rule the ball (not counting pure queries) ... it’s worth exploring and feeling both options for 2-3 days each and to understand what, where and how... this will give you bonuses, in Yii2, in fact, AR cannot be separated from the project...
Active Record is used in Ruby on Rails (from there he came to the PHP world), used in Yii2 and Laravel (Eloquent on this pattern), Data Mapper is mainly used in the world of Symfony and again Laravel The
ability to make clean queries is valued much more than the ability to work with AR - so feel free to go to work or do them in a test ... an adequate team lead will check it out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question