我目前正在尝试向我的 EmployeeCrudController 添加克隆操作。
该操作应重定向到 Action::NEW 视图并具有一些预填充值。
但是我不知道如何预填写此表格。
以下是我在 EmployeeCrudController 中定义操作的方式:
public function configureActions(Actions $actions): Actions
{
$cloneAction = Action::new('Clone', '')
->setIcon('fas fa-clone')
->linkToCrudAction('cloneAction');
return $actions->add(Crud::PAGE_INDEX, $cloneAction);
}
Run Code Online (Sandbox Code Playgroud)
这就是我的cloneAction的样子,它当前按预期重定向到Action::NEW,但没有预填充值:
public function cloneAction(AdminContext $context): RedirectResponse
{
$id = $context->getRequest()->query->get('entityId');
$entity = $this->getDoctrine()->getRepository(Employee::class)->find($id);
$clone = new Employee();
$entity->copyProperties($clone);
$clone->setFirstname('');
$clone->setLastname('');
$clone->setEmail('');
$routeBuilder = $this->get(CrudUrlGenerator::class);
$url = $routeBuilder->build([
'Employee_lastname' => 'test',
'Employee[teamMembershipts][]' => $clone->getTeamMemberships(),
])
->setController(EmployeeCrudController::class)
->setAction(Action::NEW)
->generateUrl()
;
return $this->redirect($url);
}
Run Code Online (Sandbox Code Playgroud) 我使用 EasyAdmin 的最新版本,当我提交表单时,我的add和函数将被忽略:remove
Ambiance实体:
/**\n * @ORM\\OneToMany(targetEntity="Vehicule", mappedBy="ambiance")\n */\nprotected Collection $vehicules;\n\npublic function __construct()\n{\n $this->vehicules = new ArrayCollection();\n}\n\npublic function addVehicule(Vehicule $vehicule): self\n{\n if (!$this->vehicules->contains($vehicule)) {\n $this->vehicules[] = $vehicule;\n $vehicule->setAmbiance($this);\n }\n\n return $this;\n}\n\npublic function removeVehicule(Vehicule $vehicule): void\n{\n if (!$this->vehicules->contains($vehicule)) {\n return;\n }\n\n $this->vehicules->removeElement($vehicule);\n}\n\npublic function getVehicules()\n{\n return $this->vehicules;\n}\n\npublic function setVehicules($vehicules): void\n{\n $this->vehicules = $vehicules;\n}\nRun Code Online (Sandbox Code Playgroud)\n然而我的学说映射是有效的..
\n我的 EasyAdmin 表单位于AmbianceCrudController.php:
'vehicules' => AssociationField::new('vehicules', 'V\xc3\xa9hicules'),\nRun Code Online (Sandbox Code Playgroud)\n它会生成一个multiple select2,但是当我添加车辆并提交表单时,不会插入任何数据。
如何在 Symfony EasyAdmin 3 管理表单中创建密码输入类型。在 EasyAdmin 2 中我可以使用- { property: ..., type: 'password' }
EasyAdmin 3 版本是什么?
我有一个非常基本的 symfony 5 + easyadmin 3 应用程序。我使用 make:entity 创建了两个实体:Posts 和 Categories
当我尝试编辑类别以分配帖子时,帖子未保存在数据库中。但是,如果我在帖子中添加类别,则将保存在 db 中。
知道我在这里缺少什么吗?
类别CrudController.php
public function configureFields(string $pageName): iterable
{
if (Crud::PAGE_EDIT === $pageName)
{
yield TextField::new('title');
yield DateTimeField::new('created_at')
->setFormTypeOption('disabled','disabled');
yield AssociationField::new('posts')
->autocomplete();
Run Code Online (Sandbox Code Playgroud)
实体类别.php
/**
* @ORM\OneToMany(targetEntity=Post::class, mappedBy="category")
*/
private $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
/**
* @return Collection|Post[]
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setCategory($this);
}
return …Run Code Online (Sandbox Code Playgroud) 我从 EasyAdmin v3 开始。我想在 easyAdmin 中设置默认值。在 php/symfony 中我会提供:
$article = new Article::class;
$article->setAuthor($user)
Run Code Online (Sandbox Code Playgroud)
在创建表单以在我的实体中设置 currentUser 但使用 EA3 时,我不知道如何管理它。
谢谢
如何以 symfony 日期/时间选择器时间格式更改本机 Easy admin 3?它现在呈现月、日、年。如何设置“Ymd H:i”?