E
E
Elena2019-06-17 09:25:00
symfony
Elena, 2019-06-17 09:25:00

How will it be right?

Started learning Symfony. But before that I sat on Yii2. Therefore, the study is in comparison. And in connection with this, questions arose. I'm interested in how this is accepted in Symfony. And specifically in version 4. I would like to immediately go on the right path, and not on the path of a rake.

  1. When routing in the docks, 2a approaches are recommended - routing in the config and annotations. I liked the annotations better. But what is the best way to do it? Because in Yii2, I wrote the rules for the controller / view once there and that's it.
  2. As I understand it, there are no explicit models in Symfony. Here they are entities. And this is where working with forms is very unusual for me. It turns out that you first create an entity, then a class, where you create a form, and only then you get it all in the controller. But there is a code where the creation of the form goes immediately in the controller. What is the more correct approach in this case?
  3. And a question on validation in forms. I liked the validation in annotations for entities more. But I met examples where validation was prescribed at the stage of form formation. Which approach is more correct?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2019-06-17
@prototype_denis

1. Where is more convenient for you. Annotations are just one way to store configuration.
2. From the situation. Forms do not need an entity, but some kind of class (and then, optionally) to map the data. And here also, as you prefer. For example, a form for deletion, boldly in the controller, for editing in a separate class that can be reused.
3. Holivara question. I saw people foaming at the mouth arguing that everything needs to be written in types, and others who have forms with a total number of fields exceeding 300, where only fields are registered ... It's also all from the situation. If this form will be reused, there will be different validation groups, handlers will be different, then it makes sense to leave them minimally loaded and take everything out, and vice versa, if the form is extremely specific, then it is better not to spread work with it over the application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question