ds122455 2017-05-29 14:26
浏览 39
已采纳

Symfony Sonata Admin Bundle - 预期的数字

Hey my Seance entity have following fields :

- idseance
- day
- hour
- idmovie (references to Movie entity => id)
- idromm (references to Room entity => id)

When I want to list all seances everyting is ok, I see Movie title in col, but if I try to edit seance I have following error: Unable to transform value for property path "idmovie": Expected a numeric.

The same error occurs in idroom case.

Below is my configureFormField from SeanceAdmin

   $formMapper->add('day', 'datetime', ['label' => 'Data seansu', 'format' => 'y M d']);
    $formMapper->add('hour', 'time', ['label' => 'Godzina rozpoczęcia ']);
    $formMapper->add('discountticket', 'number', ['label' => 'Cena biletu ulgowego']);
    $formMapper->add('normalticket', 'number', ['label' => 'Cena biletu normalnego']);
    $formMapper->add('idmovie', 'integer', ['label' => 'Film']);
    $formMapper->add('idroom', 'integer', ['label' => 'Sala']);

If I remove idmovie and idroom, edit page load correctyl but I can't edit movie or room value of course.

Anyone have idea why it doestn't work correctly?

  • 写回答

1条回答 默认 最新

  • dss89001 2017-05-29 16:30
    关注

    If it's not done, you need to write annotations for the idmovie/idromm fields.

    First, add this under your entity namespace : use Doctrine\ORM\Mapping as ORM;

    Then you have to annotate your fields like this :

     * @ORM\ManyToOne(targetEntity="YourBundle\Entity\Movie", cascade={"persist"})
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_movie", referencedColumnName="id")
     * })
     /
     private $idMovie;
    

    Finally, in SeanceAdmin.php, you need to replace the integer type of your field by entity or sonata_type_model

    You can see more about form field types here -> https://sonata-project.org/bundles/admin/master/doc/reference/form_types.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)