컨트롤러에서 양식 빌더로 객체를 전달하여 나중에 해당 객체를 ChoiceType 필드로 사용할 수 있습니다. 어떻게해야합니까? 이것은 내 SubAgentType.php컨트롤러에서 객체 유형 전달
class SubAgentType extends AbstractType {
protected $choices;
public function __construct (Choices $choices)
{
$this->choices = $choices;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('company_id', ChoiceType::class, array(
'mapped' => false,
'choices' => $choices,
));
문제는 내가 아래의 오류입니다
$choices = [];
$table2Repository = $this->getDoctrine()->getRepository('SwipeBundle:Company');
$table2Objects = $table2Repository->findAll();
foreach ($table2Objects as $table2Obj) {
$choices[$table2Obj->getId()] = $table2Obj->getId() . ' - ' . $table2Obj->getName();
}
$form = $this->createForm(SubAgentType::class, $choices, array(
'action'=>$this->generateUrl('backend_sub_agent_create'),
'method'=>'POST'
));
:
이 내 컨트롤러입니다. 당신의 MyFormType에서
myform.type:
class: AppBundle\Form\MyFormType
arguments:
- '@doctrine.orm.entity_manager'
tags:
- { name: form.type }
: 당신의 services.yml 파일에
:
Catchable Fatal Error: Argument 1 passed to MyBundle\Form\SubAgentType::__construct() must be an instance of MyBundle\Form\Choices,
' "myform.type"에 대한 구성을로드 할 수있는 확장명이 없습니다. – phpmeter