我正在尝试使用单选按钮显示所有类别(来自我的表类别)。有 3 个类别,但在 Doctrine 查询 OK 时只显示一个单选按钮。
我的表单类型代码:
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('categories', 'entity', array(
'class' => 'MyBundle:Category',
'expanded' => true,
'property' => 'title',
'property_path' => false,
));
}
我的树枝代码:
{{ form_widget(form) }}
结果应该返回 3 个单选按钮,但我只看到一个单选按钮(表中的第一个)。
Symfony 分析器(调试栏)中显示的 Doctrine 查询完美执行并返回 3 行。
也许问题来自我必须添加的“property_path”,否则我有一个异常:
Neither property "categories" nor method "getCategories()" nor method "isCategories()" exists in class ...
请问有什么帮助吗?
非常感谢 :-)
奥雷尔
编辑 :
这是删除“property_path”时与此请求对应的我的dev.log:
[2012-04-26 07:27:01] doctrine.DEBUG: SELECT t0.id AS id1, t0.last_update AS last_update2, t0.title AS title4 FROM category t0 ([]) [] []
[2012-04-26 07:27:01] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException". [] []
[2012-04-26 07:27:01] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException". [] []
[2012-04-26 07:27:01] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException". [] []
[2012-04-26 07:27:01] request.CRITICAL: Symfony\Component\Form\Exception\InvalidPropertyException: Neither property "categories" nor method "getCategories()" nor method "isCategories()" exists in class "Acme\MyBundle\Entity\Category" (uncaught exception) at /www/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php line 316 [] []
我真的不明白为什么它拒绝显示我的类别表的每一行......