[FLOW3-general] How to use value objects
lukas lentner
kontakt at lukaslentner.de
Tue Feb 8 19:33:08 CET 2011
Hi folks,
I've got a problem with value objects! Sadly this topic is not well explained in the manual!
1. Sometimes I get the error: "#1268309017: The object of type "F3\FamilyNetwork\Domain\Model\Value\UnknownDate" is not marked as lazy loadable.". Why should I mark it as such. I never used the @lazy on any property.
2. When I observe the database I see that only one of many value objects that should be inserted is actually there and is linked to all the objects which should be linked to own value objects (Just the Date is in the database and is also used as if it would be a location). It seems that FLOW3 tries to reuse this value object for all the others. I guess that's why I get sometimes this error: "#1244465558: Expected property of type F3\FamilyNetwork\Domain\Model\Value\Location, but got F3\FamilyNetwork\Domain\Model\Value\Date_AOPProxy_Development for F3\FamilyNetwork\Domain\Model\Person\Detail\BirthDetail::location". How does FLOW3 recognize when to reuse the v-object and when not. I gave each class different properties and set them in the constructor like this:
<?php
declare(ENCODING = 'utf-8');
namespace F3\FamilyNetwork\Domain\Model\Value;
/* *
* This script belongs to the FLOW3 package "FamilyNetwork". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License, or (at your *
* option) any later version. *
* *
* This script is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
* General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with the script. *
* If not, see http://www.gnu.org/licenses/lgpl.html *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* A date
*
* @scope prototype
* @valueobject
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
*/
class Date {
/**
* The year
*
* @var integer
*/
protected $year;
/**
* Constructs a new date
*
* @param integer $year The year
*/
public function __construct($year = NULL) {
$this->year = $year;
}
/**
* Gets the year
*
* @return integer The year
*/
public function getYear() {
return $this->year;
}
}
?>
<?php
declare(ENCODING = 'utf-8');
namespace F3\FamilyNetwork\Domain\Model\Value;
/* *
* This script belongs to the FLOW3 package "FamilyNetwork". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License, or (at your *
* option) any later version. *
* *
* This script is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
* General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with the script. *
* If not, see http://www.gnu.org/licenses/lgpl.html *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* A location
*
* @scope prototype
* @valueobject
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
*/
class Location {
/**
* The location name
*
* @var string
*/
protected $name;
/**
* Constructs a new Location
*
* @param string $name The name
*/
public function __construct($name = NULL) {
$this->name = $name;
}
/**
* Gets the name
*
* @return string The name
*/
public function getName() {
return $this->name;
}
}
?>
3. Why do I need to give every value object an constructor?
Thankx for any help!!!
Lukas
More information about the FLOW3-general
mailing list