Easyadmin 一对多:不显示表单
Easyadmin One-to-Many: not displaying form
使用 Easyadmin、Symfony3 和 Doctrine,我正在尝试显示文章的嵌入式表单以向自身添加 Urls。
但是,文章表单当前 不显示 Url 类型表单,而是显示文本框 - 看起来 - 期望 Urls 我想补充一下。
我发现以下配置应该有效(根据 this question):
form:
fields:
[...]
- { property: 'urls', type: 'collection', type_options: { entry_type: 'MyVendor\MyBundle\Form\UrlType', by_reference: false } }
文章:
class Article
{
[..]
/**
* @ORM\OneToMany(targetEntity="Url", mappedBy="article", cascade={"persist", "remove"})
*/
private $urls;
public function __construct() {
$this->urls = new ArrayCollection();
}
/**
* Add url
*
* @param Url $url
*
* @return Article
*/
public function addUrl(Url $url)
{
$url->setArticle($this);
$this->urls[] = $url;
return $this;
}
/**
* Remove url
*
* @param Url $url
*/
public function removeUrl(Url $url)
{
$this->urls->removeElement($url);
}
/**
* Get url
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getUrls()
{
return $this->urls;
}
}
Url:
class Url
{
[..]
/**
* @var Article
*
* @ORM\ManyToOne(targetEntity="Article", inversedBy="urls")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="article_id", referencedColumnName="id")
* })
*/
private $article;
/**
* Set article
*
* @param Article $article
*
* @return Url
*/
public function setArticle(Article $article = null)
{
$this->article = $article;
return $this;
}
/**
* Get article
*
* @return Article
*/
public function getArticle()
{
return $this->article;
}
}
Url类型:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('address', TextType::class);
$builder->add('description', TextType::class);
}
我已经检查、仔细检查并尝试了代码中的很多东西并搜索了 google 以及 Whosebug。
如何显示用于向文章添加新 URL 的字段?
感谢 EasyAdmin this issue has been resolved. It turns out that despite of using the fully qualified namespace to UrlType in YAML config, the type is overwritten with the Symfony UrlType 的朋友们。
解决方案:将MyVendor\MyBundle\Form\UrlType
重命名为例如MyVendor\MyBundle\Form\UrlEntityType
这看起来像是 Symfony 或 EasyAdmin 中的错误。
使用 Easyadmin、Symfony3 和 Doctrine,我正在尝试显示文章的嵌入式表单以向自身添加 Urls。
但是,文章表单当前 不显示 Url 类型表单,而是显示文本框 - 看起来 - 期望 Urls 我想补充一下。
我发现以下配置应该有效(根据 this question):
form:
fields:
[...]
- { property: 'urls', type: 'collection', type_options: { entry_type: 'MyVendor\MyBundle\Form\UrlType', by_reference: false } }
文章:
class Article
{
[..]
/**
* @ORM\OneToMany(targetEntity="Url", mappedBy="article", cascade={"persist", "remove"})
*/
private $urls;
public function __construct() {
$this->urls = new ArrayCollection();
}
/**
* Add url
*
* @param Url $url
*
* @return Article
*/
public function addUrl(Url $url)
{
$url->setArticle($this);
$this->urls[] = $url;
return $this;
}
/**
* Remove url
*
* @param Url $url
*/
public function removeUrl(Url $url)
{
$this->urls->removeElement($url);
}
/**
* Get url
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getUrls()
{
return $this->urls;
}
}
Url:
class Url
{
[..]
/**
* @var Article
*
* @ORM\ManyToOne(targetEntity="Article", inversedBy="urls")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="article_id", referencedColumnName="id")
* })
*/
private $article;
/**
* Set article
*
* @param Article $article
*
* @return Url
*/
public function setArticle(Article $article = null)
{
$this->article = $article;
return $this;
}
/**
* Get article
*
* @return Article
*/
public function getArticle()
{
return $this->article;
}
}
Url类型:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('address', TextType::class);
$builder->add('description', TextType::class);
}
我已经检查、仔细检查并尝试了代码中的很多东西并搜索了 google 以及 Whosebug。
如何显示用于向文章添加新 URL 的字段?
感谢 EasyAdmin this issue has been resolved. It turns out that despite of using the fully qualified namespace to UrlType in YAML config, the type is overwritten with the Symfony UrlType 的朋友们。
解决方案:将MyVendor\MyBundle\Form\UrlType
重命名为例如MyVendor\MyBundle\Form\UrlEntityType
这看起来像是 Symfony 或 EasyAdmin 中的错误。