[TYPO3-ect] Best way to access request parameters from model?
Elmar Hinz
elmar07 at googlemail.com
Tue Oct 2 09:04:37 CEST 2007
Hello,
after a lot of experience with lib/div and different ways tested, I am still
not sure what the best way to access parameter data from the model is.
A) Accessing the paramaters directly:
=====================================
$uid = $_POST[...][...];
$title = $_POST[...][...];
This is definitly the wrong way.
B) Taking parameters from a given request object:
=================================================
$uid = $this->parameters->get('uid');
$title = $this->parameters->get('title');
In the controller you just need to do:
$model->parameters = $this->parameters;
Or similar like lib/div currently does
$model->controller = $this->controller;
and in the model
$pars = $this->controller->parameters;
$uid = $pars['uid'];
$title = $pars['title'];
Advantages:
* There is often no typing in the controller.
* There is few typing in the model.
* Unit testing can be done by defining a parameters mock object.
Disadvantages:
* In complex forms you sometimes have to alter the parameters object
several time. That works but somehow feels wrong.
* The model depends on a lib/div like parameters object. It can't be
exported to a different environment directly. (It can be preparing
a paramtersobject there, which is not that difficult.)
B) SPL Style:
=============
In the controller something like this:
$model->exchangeArray($validator); // Validated parameters in there.
In the model:
$uid = $this['uid'];
$title = $this['title'];
Advantages:
* Looks smart and is few to type.
* Unit testing is can be done be feeding a test array or mock object.
Disadvantages:
* Quickly comes to limits for more complex objects like those having a
a list as result of the query.
C) Let's call it traditional:
=============================
For example with dedicated setter methods:
$model->setUid(...);
$model->setTitle(...);
....
Advantages:
* The objects interface is obvious and self explaining.
* A high level of security can be reached to check for valid data only.
* Unit tests are easy to write and to read.
Disadvantages:
* A lot to type.
* Difficult for autogenration or copy and paste programming.
Please give feedback?
=====================
There are a lot of different alternatives to do it.
Which one do you personally think the best one?
What can we learn from other MVC environments here?
What it the road to take for the beta branch?
Regards
Elmar
More information about the TYPO3-team-extension-coordination
mailing list