這是2.7 控制器中使用正確的方法是:
$itemform = $this->createForm(new SyllabusType(), $item, array('databranchid' => $branchid));
和形式使用本:
$builder
->add('studentclassid', 'entity', array(
'class' =>'Schoolerp\Bundle\DBBundle\Entity\Studentclass',
'choice_label' => 'name',
'empty_value' => 'Choose an option',
'query_builder'=>function(EntityRepository $e) use ($options){
return $e->createQueryBuilder('u')->where('u.isactive=1')
->andWhere('u.branchid = ?1')
->setParameter(1, $options['databranchid']);
}
))
->add('sectionid', 'entity', array(
'class' =>'Schoolerp\Bundle\DBBundle\Entity\Sections',
'choice_label' => 'name',
'empty_value' => 'Choose an option',
'query_builder'=>function(EntityRepository $e) use ($options){
return $e->createQueryBuilder('u')->where('u.isactive=1')
->andWhere('u.branchid = ?1')
->setParameter(1, $options['databranchid']);
}
));
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Schoolerp\Bundle\DBBundle\Entity\Syllabus',
'databranchid' => null
));
}
,如果你使用3.0更換輸入型進入課堂類型。
也許這將幫助你:https://stackoverflow.com/questions/10272353/pass-value-in-options-array-to-embedded-form –