Hi, what are the rules on when to put a function on model class or when to put it on controller class?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
There are without doubt people who can explain this better, but I'll go and give it a try anyway:
Basically a model (or DataObject) represents the Data in the DataTable, and has all necessary functionality to update its Data (in the CMS) and return its Data, arranged in some way or other.
The controller drives the template, it provides the template with data that it retreives from various Models, and presents in the way the template requests it.
Talking about pages, the current Page_Controller takes care of 'filling' the page's template. That's why its controller methods are accessible from within the template. A page's Model and Controller are special, in that they are aready connected: the Page Controller has acces to its Models methods (and its DataFields), so the template can access them as well.
However, once you enter the scope of a <% loop %> structure, you iterate through Models (DataObjects), so the pages that are returned by Children(), Menu() or DataObject::get() methods are Page objects - NOT Page_Controllers, so you can only access their Page methods. So all necessarey functionality in that case should come from the Model.