David Belanger
05/25/2022, 8:44 PMAdam Cameron
myControllerMethod(requestBitsAndPieces) {
someData = myModel.doStuff(requestBitsAndPieces)
renderEmailView("theSpecificEmailView", someData)
return renderResponseView("responseView", someData)
}
And here renderEmailView
handles both the the actual composition of the email content, and the transmission of same? Initially I thought that seemed like a good solution, but it's a bit tight-couply around the "render" and "transmit" pieces.
I think where the idea separates from a sound approach is this bit:
sending out an email, I see that as a View (just like when I return PDFs or Excel)For this analogy to hold, then just the rendering of the email document would be the parallel to the PDFs / Excel. The views that render the binary data for the PDF or Excel don't also send the response to the client. I agree the email content should be handled by a view, but there's still the matter of the transmission. This is why I was wondering about offloading the emailing to a sub-controller... and then evolved to it being the job of an email service that has some sort of templating / view handling itself (as per Sean's approach). And also that it's business logic that an email is even a "thing" for the given business processing being served, so - again - not for the controller.
I like the Active Record model approach to things because it keeps things simple and centered around the data. Because of that, I usually only use afterSave if it affects another model.That is very good thinking, I like that. Kinda like a trigger.
mike42780
05/26/2022, 1:09 AMmike42780
05/26/2022, 1:14 AMAdam Cameron
services
directory which were similar to models
, but free of all the DB / ORM baggage (and a lot of the rest of the kitchen-sink stuff that are included into model objects and don't really belong there).
That'd go a long way towards solving situations like this.Adam Cameron