2012-01-13 97 views
2

我想使用奏鸣曲管理生成器实现CRUD。Symfony 2使用奏鸣曲管理生成器的教条一对多嵌入表格

我有两个表和供应商和供应商联系人。 我的实体表都是这样

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功能我没有得到供应商联系的表单字段。我onlty获取标签联系

任何人都可以请帮助我。

在此先感谢。

回答

1

而不是使用'集合'类型你应该'使用sonata_type_model'

相关问题