问题描述:

I was using this fine

public function setDefaultOptions(OptionsResolverInterface $resolver)

{

$resolver

->setDefaults(array(

'category' => null,

'query_builder' => function(EntityRepository $er) {

$qb = $er->createQueryBuilder('u');

if ($someCondition) {

$qb->where('u.id = $options['id']);

}

return $qb;

Is there any way to do that becasue i don't want to do in buildform because i am using this in multiple locations

网友答案:

setDefaultOptions is intended to initialize options, that will be eventually overwritten by the real passed options, therefore you can't access the $options variable there.

If you need to have different default behaviours depending on the runtime values you can still define a method to manage it, but that will have to be called manually during buildform (eventually you can define an abstract buildform and call that function there, then extending classes will have to call parent::buildForm).

相关阅读:
Top