我想在表单类型类中调用函数。函数生成数组并写在实体存储库类中。使用该数组我将生成动态表单字段。这是实体存储库类功能。
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 的表单构建器类中的存储库函数。
提前致谢。