[TYPO3-dev] Why isn't the constructor called for the domain model?

Stephan Schuler Stephan.Schuler at netlogix.de
Tue Oct 14 18:38:44 CEST 2014


Hey there.

Well. Extbase doesn't store serialized objects as far as I know. Implementing this would be possible of course, but there is no default mechanism doing this. And thinking about that has nothing to do with your problem.

You got me slightly wrong. So let me explain.

There are situations where you actually create new objects. Using "new \MyObject" right inside of your controller for example is the most obvious. Or just throw POST data against a createAction and let the property mapper do the magic of creating objects. Those situations are meant to create new objects, which means they can rely on having __construct called -- because __construct is for new objects. Those new objects are completely now to the world, and it's up to you if you just use them and throw them away afterwards or put them in $myObjectRepository->create(). When looking at the database part (which shouldn't concern you at all, by the way) those objects have no UID unless you added them to your repository and have $persistenceManager->persistAll() triggered an any way.

On the other side there are situations where you only retrieve existing objects from the database. The most obvious one is the $myObjectRepository->findBySomething() mechanism, which clearly fetches something from the database. Another one would be any action that uses the object uid as argument (like "showAction()") and lets the property do the part of retrieving objects. Those aren't meant to rely on __construct, because those objects aren't "new" to the world but only new to your single requests PHP process.

Since both situations are likely to appear on different PHP processes, both of course deal with object creation in terms of pure PHP. But in terms of object live cycle those are quite different and only the first one is meant as "create object". And thus only the first one is implemented in a way to have __construct triggered where the later one is implemented in a way to avoid that.

When using an updateAction where you have arguments for both, the object uid as well as property update arguments, that counts as retrieving.

Regards,


Stephan Schuler
Web-Entwickler

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Website: media.netlogix.de



----------------------------
Woche der 79ers vom 27. bis 31. Oktober: Microsoft SCCM, Veeam Backup, Citrix XenDesktop, Sophos, Office365
5 Tage, 5 Themen – je 79 Euro. Jetzt anmelden unter http://it-training.netlogix.de/leistungen-angebote/79ers
----------------------------




netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Neuwieder Straße 10 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Internet: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt



-----Ursprüngliche Nachricht-----
Von: typo3-dev-bounces at lists.typo3.org [mailto:typo3-dev-bounces at lists.typo3.org] Im Auftrag von Olle Haerstedt
Gesendet: Dienstag, 14. Oktober 2014 14:50
An: typo3-dev at lists.typo3.org
Betreff: Re: [TYPO3-dev] Why isn't the constructor called for the domain model?

Quote: Stephan Schuler wrote on Mon, 13 October 2014 20:47
----------------------------------------------------
> Hey there.
>
> Do you retreive an existing object from the database?

Hi!

What do you mean, existing? It's a record in the database. Does Extbase also save the actual object, serialized?

Regards
Olle
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev


More information about the TYPO3-dev mailing list