소스 검색

[Doctrine] added a better error message when an Entity has no __toString method defined

Fabien Potencier 14 년 전
부모
커밋
c12676b0a1
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

+ 4 - 0
src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

@@ -169,6 +169,10 @@ class EntityChoiceList extends ArrayChoiceList
                 $value = $this->propertyPath->getValue($entity);
             } else {
                 // Otherwise expect a __toString() method in the entity
+                if (!method_exists($entity, '__toString')) {
+                    throw new FormException('Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).');
+                }
+
                 $value = (string)$entity;
             }