Welcome Guest, Not a member yet? Register   Sign In
Best way to send text & email notifications from within a controller

What would the best way to send email and text notifications from within a controller be?

For example, a user does something and someone else is setup to receive an email/sms notification after it is completed. I'm using DOMPDF to generate PDFs with no issues and use Sendgrid & Twilio for sending out notifications. The thing is that the notifications require views to be loaded in order to create the html. 

Should I create a library with a function for each notification?

Thanks all!

It looks like I've found the answer to my question.

Returning views as data
There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:
$string = $this->load->view('myfile', '', true);

I can build my html for the PDF this way.

Let me know if you think this is a bad way to do this.

Thank you!

I'm doing that for sending "forgot my password" email. So it works just fine.

(02-14-2020, 12:06 PM)jreklund Wrote: I'm doing that for sending "forgot my password" email. So it works just fine.

Yes, it's perfect, I had it working about a minute after I posted the reply. I've been generating some alerts via AJAX requests for a while now but am starting to implement automated reporting and more advanced notification features. 

Would it be a bad idea to use views this way inside model functions?

It can be loaded there, but I generally don't want to load that type of data inside a model. In that case I would build a library instead. I think it would be cleaner to incorporate it there.

Theme © iAndrew 2016 - Forum software by © MyBB