浏览代码

[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;
             }