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

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

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程