[TYPO3-ect] Best way to access request parameters from model?
Steve Ryan
stever at syntithenai.com
Fri Oct 12 02:10:24 CEST 2007
I like SPL style.
Static access is useful in cases but SPL style
- is less typing for passing lots of fields around
- is essential when you don't know how many data fields there might be
- the parameters object has state so extensions of the parameters object
can merge/manipulate various parameters
- the model object can be configured to interpret a parameters
object/array (for example nested child records)
If you look in the extension persistence you will find that the
tx_persistence_model class has an acceptParameters function that
interprets a parameters array/object?.
(In line with Daniels suggestion) stores the data not directly as fields
of the model but in a sub object 'data'.
This saves the internal model variables for meta data about the model or
other purposes.
The acceptParameters method also supports for 'complex forms'. If
relationships are configured for the tx_persistence_model,
acceptParameters will seek child record information in the incoming
parameters data.
I'm imagining the tx_persistence_tcaModel will also transform incoming
parameter data to match with the data type defined in meta data. Eg date
format strings to timestamp, RTE transformations ......
The extension partnerpersistencedemo shows the acceptParameters in
action with child inline editing.
I did get onto a sidetrack somewhere back there of trying to automate
form field naming from a rendering library to be friendly with this idea.
Imagine .......
- a list of forms with 'hidden empty template subforms' for any related
objects.
- javascript to allow copying subform templates and manipulating their
name parameters to to be consistent with accept parameters
- javascript to allow loading of child record data into a template subform
-
$parameters=new tx_lib_validator($this->getParameters());
if ($parameters->valid()) {
$model->acceptParameters();
$model->save();
}
Steve Ryan
Daniel Pötzinger wrote:
>
>> A) Accessing the paramaters directly:
>> =====================================
> of course not :-)
>>
>>
>> B) Taking parameters from a given request object:
>> =================================================
>>
>> $uid = $this->parameters->get('uid');
>> $title = $this->parameters->get('title');
>
> I also like this most.
> Its also like planned in 5.0 like I understand -> so you have a request
> Object, which holds all the datas which are relevant for the request.
>
>
>> B) SPL Style:
>> =============
>>
>> In the controller something like this:>
>> $model->exchangeArray($validator); // Validated parameters in there.
>
> I dont like this:
> - not very clear and readable in my eyes to have parameters in the model
> called by $this['something']
> - $this[] maybe reserved to have other things (like list of sub models)
>
> Overall I dont get used - using the iterator everywhere in lib/div
> objects (like in view/ model classes) just because its more clear to
> read something like
> $this->listItems[] (where listItem is object with spl array)
> or
> $this->data[] (where data is object with spl array)
>
>> C) Let's call it traditional:
>> =============================
>>
>> For example with dedicated setter methods:
>>
>> $model->setUid(...);
>> $model->setTitle(...);
>> ....
> Hmm I also like it because:
>
> The class will be more maintainable if using a well defined API of
> getter and setters - instead of reading everywhere in the model form
> $this->parameters
>
>> D)
> Dont like this.
More information about the TYPO3-team-extension-coordination
mailing list