• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Avoiding massive controller: where to put individual files

#11
(12-28-2014, 08:12 PM)ivantcholakov Wrote: Models contain business logic in the generic sense. Some people see them only interacting with the database, well, its a narrow interpretation. If you think that a piece of code belongs to a model, move it there.
OK this is a bit of a relief to hear I suppose, but makes me wonder what the libraries folder is really for. I'm would imagine that a Paypal library or Authorize.net library might go in there but I've also heard talk about a third_party directory which seems even more appropriate.

(12-28-2014, 08:12 PM)ivantcholakov Wrote: About the emails: Sending emails from models is not a problem. It would be nice emails to be driven by an Event system, but CodeIgniter alone does not have such.
I expect it might be necessary to send email from almost any where: controllers, libraries, models. In many cases, I send an email to our developers when an uncaught exception is encountered. Because our system is hosted on a dynamically-allocated cloud computer, we must use SendGrid to get our mail reliably delivered (Rackspace and Amazon compute instances tend to be on a mail banlist by default and so are incapable of sending mail directly). Obviously I want to route all of my mail through a single mail class/object/function. The question that arises is where does this thing live?
Reply

#12
In more abstract level I think about the libraries as models first. They are for "M" in most of the cases. The differeces are technical.

For sending emails I have adapted code from an old PyroCMS release some time ago. Here is what I've got: https://github.com/ivantcholakov/starter...ules/email
Look at this first: https://github.com/ivantcholakov/starter...events.php

I demonstrate usage for a contact page. For more use-cases you may download and old purely CodeIgniter-based PyroCMS and see what is inside.

The good thing is that later you can attach more handlers to the 'email' event (for sending notification SMS for example), without need for code modification in many places.

Here is the Event library I use (not maintained by the initial author): https://github.com/ericbarnes/CodeIgniter-Events

I still need to support PHP 5.2 this is why I stay old-fashioned. I see that Lonnie Ezell makes something about emails and events https://github.com/ci-bonfire/Sprint/blo...l/email.md , https://github.com/ci-bonfire/Sprint/blo.../events.md , but I don't have the time to watch there.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.