[TYPO3-mvc] How to check if object was created ?

Dawid Pacholczyk dpacholczyk at gmail.com
Tue Mar 8 11:01:59 CET 2011


Thanks for the tip about 
$this->objectManager->get('Tx_Ext_Domain_Model_Foo')

About that obvious if construction its so obvious that I`ve checked it 
my first atempt. i wrote here cause it didn`t work :/

My code looks like this

$temp = $this->findByExtRec($resVal['uid']);
				
				if($temp !== NULL)
					echo "jest<br />";
				else
					echo "nie ma <br />";

It always show "There is" even with empty database !


W dniu 2011-03-08 10:54, Franz Koch pisze:
> Hey,
>
>> $temp = t3lib_div::makeInstance("Tx_MyExt_Domain_Model_Record");
>> $temp = $this->findByExtRec($resVal['uid']);
>>
>> How can I check is $temp is really an object?
>
> why do you first create a empty object and then overwrite it by a method
> call again? And as of Extbase 1.3 it's recommended to use the
> $this->objectManager->get('Tx_Ext_Domain_Model_Foo') instead of
> t3lib_div::makeInstance.
>
>> Not always I`ll find an object in database so I need to check before
>> I`ll use for example $temp->getUid()
>>
>> How can I do that ?
>
> just have a look at the php documentation or google ;P
>
> if ($temp !== NULL && is_object($temp)) {
> // do something
> }
>



More information about the TYPO3-project-typo3v4mvc mailing list