コントローラからフォームビルダーにオブジェクトを渡したいので、後で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