问题描述
我正在尝试使用 easyAdmin 3.x 在两个类之间建立一个简单的 ManyToMany 关系,当我尝试显示实体 CRUD 时,我经常出现此错误:
I'm trying to do a simple ManyToMany relation between two classes with easyAdmin 3.x , when I'm trying to show entity CRUD , I have constantly this error:
salles"的教义类型字段为4",EasyAdmin 尚不支持.
The Doctrine type of the "salles" field is "4", which is not supported by EasyAdmin yet.
两个实体都存在函数__to string
Th function __to string exist for the both entity
public function __toString()
{
return $this->name;
}
我的 CrudController:
My CrudController:
namespace App\Controller\Admin;
use App\Entity\Batiment;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
class BatimentCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Batiment::class;
}
public function configureFields(string $pageName): iterable
{
return [
'name',
'salles'
];
}
}
easyadmin 3.x 不管理多条关系吗?
Does easyadmin 3.x don't manage manytomany relations?
是否有特定的方式来管理和显示这些关系?
Is there a particular way to manage and display these relations?
我发现了这个捆绑包,感谢您的帮助!
I discover this bundle and thank you for your help !
推荐答案
在 EasyAdmin 3.x 中,为所有关联映射添加了一个新的专用类型 fied.
In EasyAdmin 3.x a new dedicated type of fied has been added for all association mappings.
请使用以下内容:
namespace App\Controller\Admin;
use App\Entity\Batiment;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
class BatimentCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Batiment::class;
}
public function configureFields(string $pageName): iterable
{
return [
Field::new('id')->hideOnForm(),
Field::new('name'),
Field::new('Letter'),
ImageField::new('image'),
AssociationField::new('products')
];
}
}
这篇关于添加时出现 Symfony EasyAdmin 3.x ManyToMany 错误: .... 字段的 Doctrine 类型为“4",EasyAdmin 尚不支持该类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!