1-我有一个实体:
员工医疗服务
/**
* @ORM\Entity
* @ORM\Table(name="employee_medical_file")
*/
class EmployeeMedicalService extends BaseEntity
{
//
// Some
// Fields
//
/**
* @Assert\NotBlank
* @ORM\ManyToOne(targetEntity="PersonnelBundle\Entity\Lookup\Lookup")
* @ORM\JoinColumn(name="medical_service_id", referencedColumnName="id")
*/
private $medicalService;
//
// getters
// & setters
//
2- 另一个实体:
抬头
/**
* @ORM\Entity
* @ORM\Table(name="lookup")
* @UniqueEntity(fields="name")
*/
class Lookup extends BaseEntity
{
// const ...
const TYPE_MEDICAL_SERVICE = 'medical_service';
// more constants ...
public function __construct($type)
{
$this->type = $type;
}
//
// Some Fields
//
/**
* @var string
* --stuff--
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=50)
* @Assert\NotBlank
*/
private $type;
//getters
// &setters
现在在
员工医疗服务管理员
protected function configureFormFields(\Sonata\AdminBundle\Form\FormMapper $formMapper)
{
$msquery = $this->getModelManager()
->getEntityManager('PersonnelBundle:Lookup\Lookup')
->createQueryBuilder();
$msquery->select('l')->from('PersonnelBundle:Lookup\Lookup', 'l')->where('l.type = :type')
->orderBy('l.name', 'ASC')
->setParameter('type', 'medical_service');
$formMapper
->add(..)
->add('medicalService', 'sonata_type_model', array(
'label' => 'personnel.employee.medical_service.form.medical_service',
'property' => 'name',
'placeholder' => '',
'required' => false,
'query' => $msquery,
))
->add(..)
;
}
** 我的问题: **
我需要从 EmployeeMedicalService 管理表单中添加新查找(医疗服务)的表单,当我尝试从EmployeeMedicalService管理表单中添加新的医疗服务或新的如果Type设置为NULL,则在没有值的情况下添加查找
这是
查找管理员
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array(
'label' => 'personnel.lookup.form.name'
))
->add('type', 'hidden', array(
'label' => 'personnel.lookup.form.type',
))
;
}