[TYPO3-mvc] Problem getting an instance of an object in controller

Franz Koch typo3.RemoveForMessage at elements-net.de
Wed Apr 6 18:02:20 CEST 2011


Hey,

> <code minified...>
> case 'delete':
> $rep =
> $this->objectManager->get('Tx_Ext_Domain_Repository_ObjectRepository');
> $object = $rep->findByProperty((int)$xml->value);
> if(count($object) == '1'){
> $rep->remove($object);
> $response = '1';
> } else {
> $response = 'Delete action given, but the specified object was not found';
> }
> break;
> </code>
>
> Could it be because this object has a related object as well that should
> be deleted? Should that object be instantiated as well (thought not so...)

no. As you noticed in your other posting the result is by default a 
queryResult object. If you expect only one object to be returned, use 
(like Sebastian said) the magic method "findOneByXXXX" which will return 
either the Object or NULL.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list