Short answer, Yes your model should handle all retrieving and saving of an items details i.e. its row in the database or physical files.
So, for a longer answer, take the way com_content
works as an example.
In the front-end you create a new article (e.g. via "Submit an Article" item of the "User Menu"). This is sent of as a GET
request, with values similar to this:
format="html"
itemid="999"
option="com_content"
view="form"
layout="edit"
This request travels as follow:
index.php
receives the request and
com_content/content.php
is called when the components is required (i.e. com_content entry point).
content.php
creates controller via the JController
class.
JController
looks at the inputs (i.e. params sent in the original GET
request), figures out what component it's in and tries to firstly load a file called controller.php
in the extensions folder and then looks for a suitable class in that file. (In this case ContentController
)
content.php
then tells the $controller
object to call the execute()
with the relevant task, using this $controller->execute(JRequest::getCmd('task'));
As you can tell from the GET
request, no task
has been set in this case so the __default
task is used ( $doTask = $this->taskMap['__default'];
) In a JController the default task defaults to display
, unless you override it.
This causes the display()
method in the ContentController
class (com_content/controller.php
) to be called.
After some basic checks display()
then calls the parent
version of itself i.e. parent::display($cachable, $safeurlparams);
The JContoller
version of display()
does all the basic work like getting the view name (form
) and layout (edit
) and using those to load the right view object (ContentViewForm
).
Then it loads the model & adds it to the view as the default model. (In this case the model is contentModelForm
) It loads the right model based on the view name (form
) and the model_prefix
for the component. The model_prefix
is setup by JController
during it's __construct()
method, by taking the name of the component 'Content' & appending 'Model' to it.
After a bit more setup, the display()
method of the view ContentViewForm
is called, which is where the model data is loaded (if we were editing an article the same calls to the model would load the existing article based on a extra parameter in the GET
containing the article id a_id=99
).
It also loads the Article form
(com_content/models/forms/article.xml
) at this point for use in the tmpl
file edit.php
.
So, to setup the input side the content
fields are coming from the model (albeit an empty model for a new article) and the attributes of the fields are defined in the models matching form.
The saving of changes to the Article form takes a very similar path.
GET
portion of the request contains your article id (a_id=99
) and the option parameter that point Joomla at your component ( option="com_content"
)
POST
portion contains the form (jform
) as an array, the task being performed ( task=article.save
) and a few other housekeeping parameters.
As a result the controller type instantiated by JController
this time is a ContentControllerArticle
which extends JControllerForm
(which is used for handling form submissions etc).
Remember that dot notation task values are of the form [sub]controller.method.
The save()
method of the ContentControllerArticle
object is called briefly before calling it's parent save()
method in JControllerForm
.
At this point the save()
method does things like check access permissions, validate data against any validations defined in the form and then load the model and passes the form data to the models save()
method.
Does that help?