Answer the question
In order to leave comments, you need to log in
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']));
}
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);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question