[TYPO3-mvc] extension_builder and Repositories

Christian Kuhn lolli at schwarzbu.ch
Mon Feb 13 21:30:34 CET 2012


Hey,

On 02/13/2012 03:04 PM, Toke Herkild wrote:
> Maybe one of you can explain to me how models and repositories
> correspond to eachother.

It's actually pretty simple:
In MVC you usually have a model (say: a model for cars), a view (that 
displays a car), and a controller (that finds out which car to display 
eg. by GET parameters, instantiates the model with the data, and assigns 
it to the view).

Extbase puts another layer in between the controller and the model: A 
helper class, the repository: It takes care of finding, instantiating 
and thawing a model object (or a group of objects) and returns it/them.

For instance, your car could have a unique serial number (a property of 
your model). If your controller has an action 'detail', with this 
serialnumber given to it, it should ask the repository for this specific 
car object/model. Thus, you'll do a 
'findOneBySerialNumber($serialNumber)' to the CarRepository, and you 
will get your car model object back, that you'll assign no the view to 
show. The findBy* and findOneBy* will even work magically in extbase on 
an otherwise empty repository implementation class.

Repositories also can not only give back a single model object, but also 
a group of objects as ObjectStorage or array. This would for instance be 
the case, if you have a vendor property in your model, you could have a 
'vendorList' action in your controller, given a specific vendor name. 
The controller would then ask the repository 'Give me all cars objects 
of vendor "Audi": CarRepository->findByVendor('Audi'), it would then 
assign the given objectStorage to the view again, that iterates over it 
in a <f:for ..> list.

So: Repositories are used to find, update and add specific model objects.

HTH
Christian


More information about the TYPO3-project-typo3v4mvc mailing list