[TYPO3-mvc] RFC #8050: allow object properties to be optional (ie empty)

Martin Kutschker masi-no at spam-typo3.org
Thu Jun 3 21:13:22 CEST 2010


Pascal Jungblut schrieb:
> Hey Martin,
> 
>> When a model has validators the value may never be empty.
>>
>> Solution:
>>
>> Honour the @optional annotation for a property.
> 
> I've had the same issue and suggested to allow chaining of validators with AND and OR. Well, Robert had a very easy solution for this [1]; Just make the argument optional:
> 
> public function setFooBar($foobar = NULL) {
> 
> That worked for me so far, meaning that properties only get validated if they contain something.

That doesn't work for me:

class Tx_BallroomDancing_Domain_Model_Medium extends Tx_Extbase_DomainObject_AbstractEntity {

	/**
	 * The medium's year of production.
	 *
	 * @var integer
	 * @validate NumberRange(startRange = 1900, endRange = 2100)
	 */
	protected $year;


	/**
	 * Sets the medium's year of production.
	 *
	 * @return void
	 */
	public function setYear($year = NULL) {
		$this->year = $year;
	}

}

This code will still yell if year is not within 1900-2100. I also tried setYear($year = 0), but also
to no avail.

Note that Robert talks in his post about optional controller arguments. I'm talking about object
properties that can be empty (so optional is perhaps misleading).

Masi


More information about the TYPO3-project-typo3v4mvc mailing list