Answer the question
In order to leave comments, you need to log in
Symfony2 - how to check if an object is a specific entity?
How can such a check be done in symfony2?
There are such objects that come from the form:
Project\MediaBundle\Entity\File Object
(
[id:Project\MediaBundle\Entity\File:private] =>
[name:Project\MediaBundle\Entity\File:private] => Symfony\Component\HttpFoundation\File\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 2014-04-09 00-25-51.JPG
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 32347
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[pathName:SplFileInfo:private] => /tmp/phpBvJQSn
[fileName:SplFileInfo:private] => phpBvJQSn
)
[size:Project\MediaBundle\Entity\File:private] =>
[description:Project\MediaBundle\Entity\File:private] => описание картинки
[type:Project\MediaBundle\Entity\File:private] =>
)
Project\CurBundle\Entity\Prop Object
(
[id:Project\CurBundle\Entity\Prop:private] =>
[value:Project\CurBundle\Entity\Prop:private] => первый текст
[element:Project\CurBundle\Entity\Prop:private] =>
[property:Project\CurBundle\Entity\Prop:private] =>
[property_id:Project\CurBundle\Entity\Prop:private] =>
)
if (isEntityObject('Project\MediaBundle\Entity\File')) {
echo 'Это объект из нашего проекта типа "файл"';
}
if (isEntityObject('Project\CurBundle\Entity\Prop')) {
echo 'Это объект из нашего проекта типа "свойство"';
}
Answer the question
In order to leave comments, you need to log in
If your class is under the namespace Entity, then it should be Entity, if it is not, then you need to take these classes out of this namespace.
Entity in the context of Symfony is an ordinary class (we do not take into account the fact that when it is selected from the base, it turns into a proxy). If you need to check if a variable is a class instance, then use instanceof.
ps storing UploadedFile in Entity is not the best solution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question