當我使用:
public function configureFields(string $pageName): iterable
{
return [
AssociationField::new('XYZ')
];
}`
我收到錯誤"Object of class App\Entity\XYZ could not be converted to string"
當我添加->autocomplete()到 時AssociationField::new('XYZ'),它可以作業,但在保存時會顯示錯誤"Expected argument of type "?string", "App\Entity\XYZ" given at property path "XYZ".
使用多對一關系使用此欄位的正確方法是什么?Symfony Easy Admin 檔案https://symfony.com/doc/current/EasyAdminBundle/fields/AssociationField.html根本沒有幫助。
uj5u.com熱心網友回復:
您的物體App\Entity\XYZ將在您的關聯欄位中轉換為字串(這是標準的 symfony 物體型別)。否則無法在您的物體選擇中設定標簽。
它將嘗試使用__toString方法對其進行轉換,因此您需要將其添加到您的物體中。
例如:
/**
* @ORM\Entity(repositoryClass=XyzRepository::class)
*/
class Xyz
{
public function __toString(){
return $this->name; //or anything else
}
EasyAdmin 應該能夠猜測物體類,因此您不必像簡單的EntityType.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/461394.html
