[eluser]axiom82[/eluser]
I need to execute (A) a controller-like method that (B) interacts with a model, but © is not accessible via url (as with a controller) and (D) is instead accessible via a controller method.
Below is an example:
1) A user registers an account on website via a POST form request to the user controller (a.k.a. 'user/register'). The user controller passes new user data to the user model.
2) The user model creates the new user record from the passed data. The user model creates a new email record for the user of email_type=verify (i.e. email for user account verification).
3) A cron job on a 1-minute interval sends out a batch of verification emails based on the email records with email_type=verify. As a result, the user receives the verification email with verify link.
4) The user lost the email unexpectedly. They return to the site and click the 'Resend Verification Email' button. A POST is made to the user controller's verify() method (a.k.a. 'user/verify').
Here is where it gets indecisive:
I am creating an email controller with methods for each type of email (newsletter, account verification, etc) the website sends out, a "newsletter API so to speak". A cron job will execute the email controller method associated with the specific type of email that it is scheduled to run a job for (e.g weekly email cron). The controller method gathers the necessary data from the email model (such as user data) to generate the email message and send the message via the built-in CI email library. GREAT!
Question: which is the best approach for setting up my email API: a controller or library? Since libraries are meant to be portable, I would suggest a controller. On the other hand, a controller cannot be executed from another controller, such as with the above situation where 'user/verify' needs to execute 'email/send_user_verify'. My final decision is to build an email controller that is executed via a Remote Procedure Call called within the user controller. Does this make sense?