Reputation: 1747
I'm building a small, local app for a lab I work in. Long story short, I've written a class (call it MailParser) that can log-in to a shared Gmail account and retrieve/parse e-mails that always arrive in a standardized format. The class works great. I want the interface for it to be built in Cake. I don't know how to bring the two together appropriately, and I'm pretty confident that what I'm doing, while functional, could be much improved.
The e-mails are automated responses from a registry our university hosts; they inform researchers of students who've signed up to be in experiments.
The Cake site will basically be a UI that allows lab members to manage a database. The MailParser class needs the database; it compares information parsed out of those e-mails against information in the database to subsequently update a variety of Google Calendars (say an e-mail reads "Participant_X has signed up for Experiment_Y"; the database will know that "Experiment_Y" is being run by "Experimenter_Z" and post it to their calendar for them).
The Cake app is small and simple; "Experiments", "Experimenters", "Calendars".
I've done this:
<?php
App:users('AppController', 'Controller');
/**
* Personas Controller
*
* @property Persona $Persona
*/
class MailparsersController extends AppController {
function index($getMail=false) {
//bunch o' code
}
//bunch o' functions
}
?>
The file name is MailparsersController.php
. There's no model or view for, but I don't want there to be; ultimately, this class wil get called from a small Python app that I'd like to periodically make an http request to mylabserver.com/Mailparsers
(could use javascript, just don't want to leave a browser open all the time). My index()
function, when called, does everything it should, but returns an error page. Is there a way to let a Cakephp controller quietly do its work without returning a view at all?
The cake-based UI lets lab members 'register' their experiments and their correspondent calendars, thereby automating part of the workflow; I could just write this php myself, given its limited use, but I'm a big Cakephp fan and am always looking for ways to extend its usefulness to my purposes.
Can anyone suggest an appropriate way to bring my Mailparser functionality into my Cake app? Would this be more appropriate as a plug-in (which I've never done before)? I'd be super grateful for any help, here. Thanks!
Upvotes: 0
Views: 190
Reputation: 6721
Since you're in cake 2.x, I'm going to suggest this:
App::uses('Mailparser', 'Lib');
Alternatively, you can change your class into a component. Either way, you can use your class in any controller in your app without any issues.
Furthermore, if you're really planning to use this code in other apps in the future, a plugin is the way to go.
Upvotes: 1