【发布时间】:2013-11-28 21:55:54
【问题描述】:
我有两个表,一个叫做 Portal,另一个叫做 Categories,它们通过链接表连接,因为关系是多对多的。 代码表如下:
类分类
/**
* @var integer
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
**/
private $id;
/**
* @ManyToMany(targetEntity="Portal")
*/
private $portal;
public function __construct() {
$this->portal = new \Doctrine\Common\Collections\ArrayCollection();
}
...
课堂门户
class Portal
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ManyToMany(targetEntity="Categories")
* @JoinTable(name="portal_categories")
*/
private $categories;
public function __construct() {
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
....
我开发了以下内容 在 PortalAdmin::configureFormFields
$formMapper
->with('Portal')
->add('name', 'text', array('label' => ' Name'))
->add('description', 'text', array('label' => 'Description'))
->add('webSiteLink', 'text', array('label' => 'Web Site ','required'=> false))
->add('categories', 'sonata_type_collection',array( 'by_reference' => false))
->end();
但是,只显示一个带有弹出窗口的按钮,用于插入新类别,但我需要,只显示一个包含类别的列表并添加任意数量的类别
当我尝试这样做时:
$formMapper
->with('Portal')
->add('name', 'text', array('label' => ' Name'))
->add('description', 'text', array('label' => 'Description'))
->add('webSiteLink', 'text', array('label' => 'Web Site ','required'=> false))
->add('categories', 'sonata_type_model', array('required' => false, 'expanded' => false, 'multiple' => true, 'label' => 'Chose your categories'))
->end();
显示以下错误: Project\PortalBundle\Entity\Categories 类的对象无法转换为字符串
【问题讨论】:
标签: php symfony many-to-many sonata-admin