OK, I ended up with a solution which saved me making an extra request when
I realised I could render /bookings/invoice/%id%.pdf into a variable and
temporarily save that to the server to be attached:
public function sendConfirmation() {
$email = new CakeEmail('default');
$booking = $this->Booking->find('first', array(
'conditions'=>array('Booking.id'=>$this->Booking->id),
));
$email->viewVars(array(
'booking' => $booking
));
$invoicePath = $this->getTmpFile();
$email->template('Bookings/confirmation', 'default')
->emailformat('both')
->to($booking['Organisation']['bookings_email'])
->subject('NEAS Training System: Booking Confirmation')
->attachments(array('invoice.pdf'=>$invoicePath))
->send();
unlink($invoicePath);
}
public function getTmpFile() {
$this->autoRender = false;
$view = new View($this, false);
$view->set('booking', $this->Booking->find('first', array(
'conditions' => array('Booking.id' => $this->Booking->id)
)));
$view->viewPath = 'Bookings';
$file = $view->render('pdf/invoice', 'pdf/default');
$filename = TMP . 'invoice-'.$this->Booking->id.'.pdf';
$handle = fopen($filename, 'w+');
fwrite($handle, $file);
fclose($handle);
return $filename;
}
There may be a better way to render a view into a variable, but I got this
method from reading:
http://wp.headynation.com/cakephp-get-htmloutput-of-view-without-view-displaying-or-outputting-using-render/
HTH, Paul.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php