简体   繁体   English

错误:无法确定类“ Articles”中属性“ articlesCategories”的访问类型

[英]Error : Could not determine access type for property “articlesCategories” in class “Articles”

I am using Symfony 3.4.7 . 我正在使用Symfony 3.4.7。 I work with 3 linked entites, Article, Categorie and ArticlesCategories. 我与3个链接的实体,Article,Categorie和ArticlesCategories合作。 ArticlesCategories is the relation table. ArticlesCategories是关系表。

I would like to add and edit articles. 我想添加和编辑文章。 I wish I could Add / Edit articles, given that an article may have several Categories and vice versa. 我希望我可以添加/编辑文章,因为一篇文章可能有多个类别,反之亦然。 I have attributes specific to the relationship in the relation table , that's why I created the relation entity. 我在关系表中具有特定于该关系的属性,这就是为什么我创建了关系实体的原因。

This is the code of an Articles : 这是文章的代码:

/**
 * Articles
 *
 * @ORM\Table(name="articles")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ArticlesRepository")
 */
class Articles
{
    /**
     * @var string
     *
     * @ORM\Column(name="code_article", type="string", length=10)
     * @ORM\Id
     */
    private $codeArticle;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="text", nullable=true)
     */
    private $description;

    /**
     * @var ArticlesCategories
     *
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\ArticlesCategories", mappedBy="codeArticle")
     */
    private $articlesCategories;
    // getters et setters normaux
...
    /**
     * Add articlesCategorie
     *
     * @param ArticlesCategories $articleCategorie
     *
     * @return Articles
     */
    public function addArticlesCategorie(ArticlesCategories $articleCategorie){
        $this->articlesCategories[] = $articleCategorie;
        $articleCategorie->setCodeArticle($this);

        return $this;
    }

    /**
     * remove articlesCategorie
     *
     * @param ArticlesCategories $articlesCategorie
     */
    public function removeArticlesCategorie(ArticlesCategories $articlesCategorie){
        $this->articlesCategories->removeElement($articlesCategorie);
    }

    /**
     * Get articlesCategories
     *
     * @return Collection
     */
    public function getArticlesCategories(){
        return $this->articlesCategories;
    }

    public function __toString()
    {
        return $this->codeArticle;
    }

    public function __construct()
    {
        $this->articlesCategories = new ArrayCollection();
    }

This is the code of the relation ArticlesCategories: 这是关系ArticlesCategories的代码:

/**
 * ArticlesCategories
 *
 * @ORM\Table(name="articles_categories")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ArticlesCategoriesRepository")
 */
class ArticlesCategories
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Articles", inversedBy="articlesCategories")
     * @ORM\JoinColumn(referencedColumnName="code_article", nullable=false)
     */
    private $codeArticle;

    /**
     * @var string
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Categories")
     * @ORM\JoinColumn(referencedColumnName="reference", nullable=false)
     */
    private $codeCategorie;

    /**
     * @var string
     *
     * @ORM\Column(name="critere_rech_1", type="string", length=45, nullable=true)
     */
    private $critereRech1;

    /**
     * @var string
     *
     * @ORM\Column(name="critere_rech_2", type="string", length=45, nullable=true)
     */
    private $critereRech2;

And my entite Categories has nothing specific. 我的实体类别没有具体规定。

I generate automatically the crud of my entitie Articles, then I edit the class ArticlesType to have all attributes of my relation ArticlesCategories who are displays. 我会自动生成整个Articles的分类,然后编辑ArticlesType类,使其具有我所显示的ArticlesCategories关系的所有属性。 To do this edition I use CollectionType. 为此,我使用CollectionType。

This the code of my Form ArticlesType : 这是我的Form ArticlesType的代码:

class ArticlesType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('codeArticle')
            ->add('description')
            ->add('ecotaxe')
            ->add('qteMaxCde')
            ->add('publication')
            ->add('designation')
            ->add('taxonomie')
            ->add('referenceStock')
            ->add('articleRegroupement')
            ->add('articleAssocie1')
            ->add('articleAssocie2')
            ->add('articleAssocie3')
            ->add('seuilDegressif')
            ->add('tauxDegressif')
            ->add('articlesCategories', CollectionType::class, array(
                'entry_type' => ArticlesCategoriesType::class,
                'allow_add' => true,
                'allow_delete' => true,
                'prototype' => true,
                'by_reference' => false,
                'label' => 'test',
                'attr' => array('class' => 'collection-articlesCategories'),
                'auto_initialize' => true
            ));
    }

    public function getName(){
        return 'Articles';
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundle\Entity\Articles'
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'appbundle_articles';
    }


}

When I go on the Article edition page that was generates by Symfony, I get the right display. 当我进入由Symfony生成的Article Edition页面时,我得到正确的显示。 Edition page But When I click on the button "Edit", I get this error : Could not determine access type for property "articlesCategories" in class "AppBundle\\Entity\\Articles". 版本页面但是,当我单击按钮“编辑”时,出现此错误:无法确定类“ AppBundle \\ Entity \\ Articles”中属性“ articlesCategories”的访问类型。

I don't see where is my mistake. 我看不出我的错误在哪里。

I hope I am clear. 我希望我清楚。

Thank you for help. 谢谢你的帮助。

Try putting the following: 尝试放入以下内容:

public function setArticlesCategories(...) {
 ...
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在类“ App \\ Entity \\ GameGenre”中无法确定属性“游戏”的访问类型: - Could not determine access type for property “games” in class “App\Entity\GameGenre”: 无法确定类“ AppBundle \\ Entity \\”中属性“ skills”的访问类型 - Could not determine access type for property “skills” in class “AppBundle\Entity\” 嵌入表单集合错误:无法确定属性的访问类型 - Embed a Collection of Forms Error: Could not determine access type for property Symfony - 无法确定属性“id”的访问类型 - Symfony - Could not determine access type for property “id” 无法确定 class “App\Form\OrderType”中的属性“offerOrders”的访问类型:该属性都不是 - Could not determine access type for property “offerOrders” in class “App\Form\OrderType”: Neither the property 无法确定属性“文件”的访问类型 - Could not determine access type for property "file" 无法确定 class “App\Entity\XXXX”中属性“image”的访问类型。 Symfony 4 - EasyAdmin 3.2 - VichUploader - Could not determine access type for property “image” in class “App\Entity\XXXX”. Symfony 4 - EasyAdmin 3.2 - VichUploader Symfony 4 | ManyToMany关系-无法确定属性的访问类型 - Symfony 4 | ManyToMany Relation - Could not determine access type for property 无法使用Sonata管理项目和Sonata翻译包确定Symfony 3.2。*中属性“翻译”的访问类型 - Could not determine access type for property “translations” in Symfony 3.2.* with Sonata admin project and Sonata translation bundle 无法确定属性“ id”的访问类型-HandleRequest失败,除非我将实体ID公开 - Could not determine access type for property “id” - HandleRequest failing unless I make the entity id public
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM