V
V
Vladimir2020-03-09 18:04:31
symfony
Vladimir, 2020-03-09 18:04:31

symfony. How to handle duplicate code in a controller?

The controller has two methods new and edit . Which essentially new creates a new post and edit edits itself. So, there is a piece of code (I see no reason to show it) when adding a new article (new) and which processes the file name (picture) and uploads it to the server. And there is an article editing (edit) which allows you to upload the file in the same way. And there is the same piece of code as in the new method.

Whether it is possible to carry out somehow it in a separate method correctly ? It's just that somehow I did not find any examples or anything about this in the documentation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-03-09
@prity

Take it to a separate service and here . If there is duplication of code that cannot be taken out to the service, you can go for the creation of some auxiliary private method. But without the code, I will not tell you how best to proceed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question