3341 Posts in 982 Topics by 703 members
|Go to End|
20 February 2009 at 3:57pm
Many times i've scratched my head over a problem because i've put a function in the controller rather than the model. This might sound silly - but I find having them both in the same file is very confusing.
Coming from Rails, the seperation is explicit with model files and controller files. Does anyone else think it would be much clearer to have 'mysite/code' split into 'mysite/code/controllers' 'mysite/code/models'?
Please throw in your two cents....
20 February 2009 at 5:38pm
Yeah, this confused me for a while, too. See the "Model or Controller?" post in the archive.
Functions in the controller are only available to the template being controlled by the controller. Functions in the model are available everywhere. If you've syndicated your NewsArticle objects to the home page, for instance, only the functions in the NewsArticle model will be available. But when viewing the actual NewsArticle.ss page, you'll have access to its controller functions.
Just a question of scope, really. It's a little more tidy to keep template-specific functions in your controller.
20 February 2009 at 5:56pm
Hi Mr Cheese,
I do understand the scope of a MVC system. I just don't think MVC is shouted about enough for new developers coming to silverstripe. I think having a model and controller side by side in the same file confuses new silverstripe developers.
I think to encourage the separation of business logic from template-specific actions, a model should be in it's own file. As should a controller be in it's own file.
23 February 2009 at 2:32am
Keeny, actually you could separate the files without problems, but what i noticed is one of the most common problems to new people using silverstripe is that forget to put its AnyPageController extends Page_Controller at the bottom of its Classes, imagine now they will need to create an empty file only for write this...
i think is better to simplify things, and when you start to do complex stuff, simply re order as you want
|Go to Top|