我想調用表單類的函數。函數生成數組並寫入實體庫類中。使用該數組我將生成動態表單字段。 這裏是實體庫類的功能。如何在symfony2中的表單類型中調用實體庫的函數
public static $roleNameMap = array(
self::ROLE_SUPER_ADMIN => 'superAdmin',
self::ROLE_MANAGEMEN => 'management',
self::ROLE_MANAGERS => 'manager',
self::ROLE_IT_STAFF => 'itStaff',
self::ROLE_CS_CUSTOMER => 'csCustomer',
self::ROLE_CS => 'cs',
self::ROLE_DEALER => 'dealer',
self::ROLE_ACCOUNT_STAFF => 'accountStaff',
self::ROLE_BROKER_USER => 'staff',
);
public function getGroupListArray()
{
$qb = $this->createQueryBuilder('g')
->orderBy('g.hierarchy','ASC');
$query = $qb->getQuery();
$groupList = $query->execute();
$roleNameMap = array();
foreach ($groupList as $role){
$roleNameMap[$role->getId()] = $role->getRole();
}
return $roleNameMap;
}
下面是我的表單構建器類,我想調用上面的實體存儲庫函數。
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('routeId', 'hidden');
foreach (GroupListRepository::$roleNameMap as $key=>$value){
$builder->add($value, 'checkbox',array('label' => '', 'required' => false,));
}
}
我能夠得到的靜態變量顯示在上面的代碼,但是,我有困惑,我應該如何訪問存儲庫函數的形式生成器類中的Symfony2。
在此先感謝。