17452 Posts in 4473 Topics by 1971 members
|Go to End|
10 May 2008 at 2:24am
This may sound like a really basic question, but after developing several sites with SS, I'm still unclear on which functions belong in the Model and which belong in the Controller. Both seem to work for me most of the time when I call them from the template. Is this just a question of code organization or are there really some important rules I should be following? I know with most MVC's you want to do all of your database work in the Model and any manipulation of data in the controller. Are those the general guidelines for SS, too?
10 May 2008 at 12:49pm
Yeah, those are the general guidelines.
It's more of an abstract philosophy than a set of hard-and-fast rules, but one way to think about it is: put anything that might be able to be accessed through a different interface in the model.
The model contains code that defines the "business logic" of the application you're making. The controller contains code that is specific to the particular interface you're making.
For example, in version 2.3, we're going to be releasing a RESTful API that will talk to the model layer. So, if there's anything that might be usefully accessed from a RESTful API, then it should be put into the model layer.
It also helps to ask theoretical questions about your application: "if I were going to build a mobile version of the site with a different interface, which pieces of code would I want to re-use?" That is the kind of code that you should put into the model.
However, if possible, anything that is specifically tied to the particular user-interface that you're building should be put into the controller.
|Go to Top|