使用奏鸣曲管理生成器的 Symfony 2 嵌入形式用于教义一对多关系
我正在尝试使用 sonata admin 生成器来实现 CRUD。
我有两个表和供应商以及供应商联系人。 我的实体表是这样的
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="vendor")
*/
class Vendor{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="VendorContact", mappedBy="vendor_contact")
*/
public $contact;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
* @ORM\Column(type="string", length=100)
*/
protected $userName;
/**
* @ORM\Column(type="string", length=100)
*/
protected $password;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="date")
*/
protected $contractBeginDate;
/**
* @ORM\Column(type="date")
*/
protected $contractEndDate;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $updatedAt;
public function __construct()
{
$this->contact = new ArrayCollection();
}
我的供应商联系实体类是这样的
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="vendor_contact")
*/
class VendorContact{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Vendor", inversedBy="contact")
* @ORM\JoinColumn(name ="vendor_id", referencedColumnName="id")
*/
protected $vendorContact;
/**
* @ORM\Column(type="string", length=1000)
*/
protected $street;
/**
* @ORM\Column(type="string", length=100)
*/
protected $city;
/**
* @ORM\Column(type="string", length=100)
*/
protected $state;
/**
* @ORM\Column(type="string", length=100)
*/
protected $country;
/**
* @ORM\Column(type="string", length=50)
*/
protected $zip;
/**
* @ORM\Column(type="string", length=50)
*/
protected $contact_numb;
/**
* @ORM\Column(type="string", length=100)
*/
protected $email;
/**
* @ORM\Column(type="integer")
*/
protected $contact_type;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $updatedAt;
我的奏鸣曲管理类是这样的:
class VendorAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('name')
->add('user_name','text')
->add('password','text')
->add('status')
->add('contract_begin_date','date')
->add('contract_end_date','date');
$formMapper->add('contact', 'collection', array('type' => new VendorContactType()));
// ->end();
;
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('name')
->add('userName')
->add('contractBeginDate')
->add('contractEndDate')
->add('_action', array(), array(
'actions' => array(
'edit' => array(),
),
))
;
}
}
供应商联系表单生成器是这样的:
class VendorContactType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('street')
->add('city')
->add('state')
->add('country')
->add('zip')
->add('contact_numb')
->add('email')
->add('contact_type')
;
}
public function getName()
{
return 'vendor_contact';
}
public function getDefaultOptions(array $options){
return array('data_class' => 'JiniVod\StoreBundle\Entity\VendorContact');
}
}
但是当我执行此添加供应商使用到奏鸣曲管理 CRUD 功能时,我没有得到供应商联系表单字段。我只得到标签联系方式
任何人都可以帮助我吗?
提前致谢。
I am trying to implemet CRUD using sonata admin generator.
I have two table and Vendor and vendor contacts.
My entity tables are like this
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="vendor")
*/
class Vendor{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="VendorContact", mappedBy="vendor_contact")
*/
public $contact;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
* @ORM\Column(type="string", length=100)
*/
protected $userName;
/**
* @ORM\Column(type="string", length=100)
*/
protected $password;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="date")
*/
protected $contractBeginDate;
/**
* @ORM\Column(type="date")
*/
protected $contractEndDate;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $updatedAt;
public function __construct()
{
$this->contact = new ArrayCollection();
}
And my vendor contact entity class is like this
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="vendor_contact")
*/
class VendorContact{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Vendor", inversedBy="contact")
* @ORM\JoinColumn(name ="vendor_id", referencedColumnName="id")
*/
protected $vendorContact;
/**
* @ORM\Column(type="string", length=1000)
*/
protected $street;
/**
* @ORM\Column(type="string", length=100)
*/
protected $city;
/**
* @ORM\Column(type="string", length=100)
*/
protected $state;
/**
* @ORM\Column(type="string", length=100)
*/
protected $country;
/**
* @ORM\Column(type="string", length=50)
*/
protected $zip;
/**
* @ORM\Column(type="string", length=50)
*/
protected $contact_numb;
/**
* @ORM\Column(type="string", length=100)
*/
protected $email;
/**
* @ORM\Column(type="integer")
*/
protected $contact_type;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $updatedAt;
My sonata Admin class is like:
class VendorAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('name')
->add('user_name','text')
->add('password','text')
->add('status')
->add('contract_begin_date','date')
->add('contract_end_date','date');
$formMapper->add('contact', 'collection', array('type' => new VendorContactType()));
// ->end();
;
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('name')
->add('userName')
->add('contractBeginDate')
->add('contractEndDate')
->add('_action', array(), array(
'actions' => array(
'edit' => array(),
),
))
;
}
}
And vendor contact form builder is like this:
class VendorContactType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('street')
->add('city')
->add('state')
->add('country')
->add('zip')
->add('contact_numb')
->add('email')
->add('contact_type')
;
}
public function getName()
{
return 'vendor_contact';
}
public function getDefaultOptions(array $options){
return array('data_class' => 'JiniVod\StoreBundle\Entity\VendorContact');
}
}
But when i am executing this add vendor using to sonata admin crud function i am not getting form field for vendor contact. I am onlty getting label contact
Can any one please help me.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该“使用 sonata_type_model”,而不是使用“集合”类型
Instead of using the 'collection' Type you should 'use sonata_type_model'