我明白了
“App\Entity\ObjectxDescription”类型的预期参数,“字符串”在属性路径“描述”中给出。
当我尝试从中保存数据时TextEditorField
,出现上述错误。该字段正确显示内容并在 Crud Controller 中定义。我使用表单创建 CRUD 控制器来编辑名称和描述。名称变量在Objectx
实体中,描述在ObjectxDescription
实体中。
粗鲁控制器:
<?php
//src/Controller/Admin/ObjectxCrudController.php
namespace App\Controller\Admin;
use App\Entity\Objectx;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use App\Entity\ObjectxDescription;
class ObjectxCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Objectx::class;
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setEntityLabelInSingular('Object')
->setEntityLabelInPlural('Objects')
->setPageTitle('index', 'Objects')
;
}
public function configureFields(string $pageName): iterable
{
return [
TextField::new('name','Name'),
TextEditorField::new('description','Description')
];
}
}
Objectx 实体:
<?php
//src/Entity/Objectx.php
namespace App\Entity;
use App\Repository\ObjectxRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ObjectxRepository::class)
*/
class Objectx
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToOne(targetEntity=ObjectxDescription::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
*/
private $description;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?ObjectxDescription
{
return $this->description;
}
public function setDescription(ObjectxDescription $description): self
{
$this->description = $description;
return $this;
}
}
ObjectxDescription 实体:
<?php
// src/Entity/ObjectxDescription.php
namespace App\Entity;
use App\Repository\ObjectxDescriptionRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ObjectxDescriptionRepository::class)
*/
class ObjectxDescription
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
public function __toString()
{
return $this->description;
}
public function getId(): ?int
{
return $this->id;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
}