【问题标题】:Symfony2 : displaying form entity field type as radio buttonsSymfony2:将表单实体字段类型显示为单选按钮
【发布时间】:2012-04-25 18:20:19
【问题描述】:

我正在尝试使用单选按钮显示所有类别(来自我的表类别)。 有 3 个类别,但在 Doctrine 查询 OK 时只显示一个单选按钮。

我的 FormType 代码:

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 [] []

我真的不明白为什么它拒绝显示我的类别表的每一行......

【问题讨论】:

  • 'property_path' 选项只影响表单的绑定。你读过日志吗?可能有错误。
  • 查看我对 dev.log 对应的编辑...
  • 还有什么帮助吗?我怎样才能显示我的 3 个单选按钮?为什么没有全部找回?

标签: symfony symfony-forms


【解决方案1】:

问题是我的实体设置不正确。 $id 字段是布尔值而不是整数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    相关资源
    最近更新 更多