D
D
d999992021-03-06 20:17:29
symfony
d99999, 2021-03-06 20:17:29

Is it correct to pass a value object to a view in a Symfony application, or is it more correct to get values ​​from it and pass it to a view?

controller

$formData = $form->getData();
        if ($form->isSubmitted() && $form->isValid()) {
            $contactService->send(new ContactUsValueObject('Contact form message', $formData['fullname'], $formData['email'], $formData['email'], $formData['message']));
        }


Service
public function send(ContactUsValueObject $contactUsValueObject, string $renderTemplate): bool
    {
        $message = (new \Swift_Message($contactUsValueObject->getTitle()))
            ->setFrom($contactUsValueObject->getEmail())
            ->setTo($this->parameterBag->get('contact_email'))
            ->setBody(
                $this->twig->render(
                    $renderTemplate,
                    [
//value object here
                    ]
                ),
                'text/html'
            );

        return (boolean)$this->mailer->send($message);
    }


Is it correct to write

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question