多くのコレクションを持つ親フォームがありますが、コレクションの数を制限したいので、結果の数を8に制限する基準を作成しました。これは表示には問題なく機能しますが、編集中は機能しません。
次のエラーが発生します。
「クラス「App \ Entity \ Parent」のプロパティ「Collections」のアクセスタイプを判別できませんでした:プロパティ「Collections」もメソッド「addCollections()」/「removeCollections()」、「setCollections()」のいずれもありません。 「Collections()」、「__ set()」、または「__call()」が存在し、クラス「App \ Entity \ Parent」にパブリックアクセス権があります。
これはおそらく、デフォルトの代わりにを$this->Collections->matching($criteria)
返すためArrayCollection
ですPersistentCollection
。
ここから先に進む方法がわかりません。
誰かが私にいくつかの提案や参考資料を教えてもらえますか?
/**
* @ORM\OneToMany(targetEntity="App\Entity\Collection", mappedBy="parent", cascade={"persist"}, orphanRemoval=true)
* @ORM\OrderBy({"createdOn" = "DESC"})
*/
private $Collections;
public function __construct()
{
$this->Collection; = new ArrayCollection();
}
public function getCollections(): Collection
{
$criteria = Criteria::create()
->setMaxResults(8);
return $this->Collections->matching($criteria);
}
プロパティ$collections
がprivate
(ではなくpublic
)であり、そのためのsetter-methodもないため、この例外が発生します。
このように、フォームコンポーネント$collections
は外部からの値を設定できません。
setCollections
次のようにメソッドを追加します。
/** @var Collection */
private $collections;
public function __construct()
{
$this->collections = new ArrayCollection();
}
public function setCollections(?Collection $collections)
{
foreach ($collections as $collection) {
$collection->setParent($this);
}
$this->collections = $collections;
}
次に'by_reference' => false
、collections
フィールドのフォームタイプにオプションを設定します。
あなたはおそらく、あなたの名前を変更するCollection
ような、より意味のあるものに実体をCar
か、Picture
および使用$cars
または$pictures
あまりにも、。:)
さらに、プロパティ名と大文字と小文字の不一致を再確認してください。
protected $collections
->小文字__construct
方法:コレクションS - >小文字、末尾に「s」を追加します。この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加