public function action_download($id = null) { if($id == null) exit; if(file_exists(APPPATH . 'path/to/file.pdf')) \File::download(APPPATH . 'path/to/file.pdf'); }
public function action_email($id = null) { if($id == null) exit; $data = //some data // Create an instance $email = \Email::forge(); // Set the from address $email->from('person@domain.com', 'From Me'); $email_to = // DB query to get the email recipients as an array $emails = array(); foreach($email_to as $to) { $emails[$to['email']] = $to['first_name'] . ' ' . $to['last_name']; } // Set a subject $email->subject('Subject'); // Set multiple to addresses $email->to($emails); // And set the body. $email->html_body(\View::forge('module/email', $data)); if(file_exists(APPPATH . 'path/to/file.pdf')) $email->attach(APPPATH . 'path/to/file.pdf'); try { $email->send(); } catch(\EmailValidationFailedException $e) { // The validation failed } catch(\EmailSendingFailedException $e) { // The driver could not send the email } if( ! \Input::is_ajax()) { \Session::set_flash('success', 'Emails successfully sent!'); \Response::redirect(\Session::get('prevurl')); } }
if ( ! \Input::is_ajax()) { \Session::set_flash('success', 'Emails successfully sent!'); \Response::redirect(\Session::get('prevurl')); }I use the shutdown event to save the previous url in a session. So, of course, when I visit the download link it saves that url, then when I click the email url it it tries to redirect back to the download page since that was the last url visited. Looks like I'll just need to write a check in the shutdown event so that it doesn't capture anything from the download action. Thanks for taking the time to help!
It looks like you're new here. If you want to get involved, click one of these buttons!