* Justin French <[EMAIL PROTECTED]>: > Any MVC pattern gurus out there? I have a quick question on app design > following an MVC pattern (which I'm attempting for the first time). > > Let's say I have two controllers, home and news. Both of these > controllers will access the news data, and will need to access a > library of functions that retrieve that news data out of the database, > manipulate it, etc. > > My first guess was that a function to retrieve news items and prepare > them for use in the View would be declared in the Controller. However, > since two Controllers want to do the same thing, this doesn't make > sense. (I'm a big fan of DRY too (Don't Repeat Yourself). > > So I'm guessing these news related functions need to exist in an > external library shared & accessed by both Controllers, however this > means that each controller isn't truly self-contained. > > Or maybe the Model is more than just data, and the functions used to > retrieve and prepare the data for use in the View are part of the > Model??
That's how I tend to think of MVC and use it in practice. Typically, I develop an API for accessing the data, and this contains all the business logic -- if data is of this type, insert these extra entries in this link table, etc. The database plus the business logic make up the Model, then. My controller scripts then use the APIs for fetching and manipulating the data, and then pass content to the templates (the View). I never think of the controller scripts as self-contained; I think of them as traffic controllers. They take input from the user, interpret that into requests to the Model, then take any information returned by the model and pass it to the view, and then take the content returned by the view and return it to the user. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php