![](/img/trans.png)
[英]Could not determine access type for property “games” in class “App\Entity\GameGenre”:
[英]Error : Could not determine access type for property “articlesCategories” in class “Articles”
我正在使用Symfony 3.4.7。 我與3個鏈接的實體,Article,Categorie和ArticlesCategories合作。 ArticlesCategories是關系表。
我想添加和編輯文章。 我希望我可以添加/編輯文章,因為一篇文章可能有多個類別,反之亦然。 我在關系表中具有特定於該關系的屬性,這就是為什么我創建了關系實體的原因。
這是文章的代碼:
/**
* 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();
}
這是關系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;
我的實體類別沒有具體規定。
我會自動生成整個Articles的分類,然后編輯ArticlesType類,使其具有我所顯示的ArticlesCategories關系的所有屬性。 為此,我使用CollectionType。
這是我的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';
}
}
當我進入由Symfony生成的Article Edition頁面時,我得到正確的顯示。 版本頁面但是,當我單擊按鈕“編輯”時,出現此錯誤:無法確定類“ AppBundle \\ Entity \\ Articles”中屬性“ articlesCategories”的訪問類型。
我看不出我的錯誤在哪里。
我希望我清楚。
謝謝你的幫助。
嘗試放入以下內容:
public function setArticlesCategories(...) {
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.