小编use*_*133的帖子

Symfony2,关系表格中的manyToMany

我开始学习sf2,非常酷,因为我的问题我有两个表:

媒体

/**
 * @ORM\ManyToMany(targetEntity="Test\SiteBundle\Entity\Website", inversedBy="medias")
 * @ORM\JoinTable(name="media_website")

private $websites;
Run Code Online (Sandbox Code Playgroud)

网站

/**
 * @ORM\ManyToMany(targetEntity="Test\SiteBundle\Entity\Media", mappedBy="websites")

private $medias;
Run Code Online (Sandbox Code Playgroud)

在我的MediaType.php中我有这个:

$builder
        ->add('title')
        ->add('website', 'entity', array(
            'class'         =>  'TestSiteBundle:Website',
            'property'  =>  'name',
            'query_builder' => function(WebsiteRepository $er)use($user_id) {
                               return $er->getMyWebsites($user_id);
             },
            'multiple'=>false))
Run Code Online (Sandbox Code Playgroud)

最后,在枝条页面中我有这个:

<div class="form-group">
   {{ form_label(form.description, "Description", { 'label_attr': {'class': 'control-label col-md-2'} }) }}
   <div class="col-md-5">
        {{ form_widget(form.description, { 'attr': {'class': 'form-control'} }) }}
   </div>
</div>
Run Code Online (Sandbox Code Playgroud)

当我尝试添加媒体时出现此错误:

Neither the property "websites" nor one of the methods "setWebsites()", "__set()" or "__call()" exist and …
Run Code Online (Sandbox Code Playgroud)

many-to-many symfony-forms symfony doctrine-orm

0
推荐指数
1
解决办法
1250
查看次数