Hello, I am almost ok with this method, but ... - the set*ContentResolver are ... quite complicated, can it be more magic, or optional ? - this should me an sfMail class which handle array as constructor. This will allow to quickly build an email. - how can we access to an image reference inside the template ?
one more thing : The send method should take an optional argument to set the default mail gateway. (think like database connection definition) Thomas On Mon, Sep 15, 2008 at 5:44 PM, Kris Wallsmith <[EMAIL PROTECTED]> wrote: > > +1 for putting this in factories.yml and extending sfContext to accept > custom factories from plugins and the project. > > It's my understanding the 2.0 service container will be flexible in > this way (per Fabien's presentation at sf camp), so this change to > sfContext would also serve forward compatibility. > > Kris > > On Sep 15, 2008, at 8:25 AM, "Nicolas Perriault" > <[EMAIL PROTECTED]> wrote: > >> >> On Mon, Sep 15, 2008 at 3:17 PM, Thomas Rabaix <[EMAIL PROTECTED] >> > wrote: >> >>> My assumptions : sf1.0 has a nice way to handle mail : easy to use >>> and >>> quickly understanble by everyone. Agree ? >> >> Well, do you mean that? http://www.symfony-project.org/cookbook/1_0/en/email >> >> I don't like that much the "all-in-the-controller" approach, even if >> it's true that you can move the code into another protected method, >> even in a parent stub class (actually that's what I've done in >> symfonians.net, but I'm not happy with it, even if it works). >> >>> $this = Controller >>> >>> $this->sendMail(array( >>> 'mailClass' => 'sfMail', >>> 'action' => 'module/mail', >>> 'template' => 'my_template', >>> 'layout' => ''email_layout', >>> 'vars' => array( >>> 'invoice' => $invoice, >>> 'file' => new sfFile(), // can generate a unique identifier for >>> the file >>> ); >>> )); >>> >>> of course some of this value could be guessed by the sendMail or >>> defined in a yml file. >> >> With what I've in mind, mail sending in your action would be quite >> similar to: >> >> $email = new InvoiceEmail(); >> $email->setVars(array('invoice' => $invoice)); >> // may be $email->addVar('invoice', $invoice); >> $email->send(); >> >> And in InvoiceEmail.class.php >> >> class InvoiceEmail extends BaseEmail >> { >> public function configure() >> { >> $this->setHtmlContentResolver(sfEmail::FROM_ACTION, array('mail', >> 'invoice')); >> $this->setTextContentResolver(sfEmail::FROM_ACTION, array('mail', >> 'invoice'), array('sf_format' => 'txt')); // notice the sf_format >> trick >> // or $this->contentResolvers['text/html'] = new >> sfEmailTemplateAction('mail', 'module'); ? >> >> $invoice = $this->getVar('invoice'); >> >> $this->setSubject(sprintf('Your order #%s', $invoice- >> >getOrderNumber())); >> $this->addTo($invoice->getCustomer()->getEmail()); >> $this->addBCC('[EMAIL PROTECTED]'); >> $this->attachFile($invoice->asPDF(), 'invoice.pdf', 'application/ >> pdf'); >> } >> } >> >> Two templates should then exist in the mail module templates folder, >> invoiceSuccess.php and invoiceSuccess.txt.php. Okay, I don't like the >> set*ContentResolver method calls but I guess that's why I'm asking for >> better ideas here ;-) >> >> The idea here is to move the email logic from the controllers to >> something apart, as what has been done with forms. >> >>> As the sendMail is not welcome anymore in the controller, a mail >>> class >>> (let's say sfMailComponent) can register to listen [1] to the >>> controller.method_not_found event, and retrieve 'sendMail' call. >> >> Way hacky, isn't it? I don't know. People, express yourself :-) >> >> ++ >> >> -- >> Nicolas Perriault >> http://prendreuncafe.com - http://symfonians.net - http://sensiolabs.com >> Phone: +33 660 92 08 67 >> >> > > > > > -- Thomas Rabaix Internet Consultant --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-devs?hl=en -~----------~----~----~----~------~----~------~--~---
