Symfony5 – repository in action controller is it correct?

is it correct to use repository in action? or maybe should i make another service and put it there?

/**
 * @Route("/process/{pid}/add/dictionary/{did}", name="app_add_dictionary_to_process")
 * @ParamConverter("dictionary", options={"id" = "did"})
 * @ParamConverter("process", options={"id" = "pid"})
 */
public function addDictionaryToProcess(Process $process, Dictionary $dictionary, ProcessDictionaryRepository $repository, ProcessDictionaryLinkRegisterer $registerer)
{
    $processDictionary = $repository->findOneBy([
        'process' => $process,
        'dictionary' => $dictionary
    ]);

    if ($processDictionary === null) {
        $registerer->register($process, $dictionary);
        $this->addFlash("success", "success");
    } else {
        $this->addFlash("error", "err");
    }

    return $this->redirectToRoute("app_process_dictionaries_manage", ["id" => $process->getId()]);
}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *