可捕获的致命错误:传递给(...)\ Handler \ FlightHandler :: __ construct()的参数1必须是Symfony \ Component \ Form \ Form的实例

时间:2015-11-02 11:01:16

标签: symfony

我有一个大错误,只花了2个小时的时间...... 我在FlightType中更改了configureOptions方法,但它不是解决方案。

错误:

  

捕获致命错误:参数1传递给   Test \ FrontBundle \ Form \ Handler \ FlightHandler :: __ construct()必须是   Symfony \ Component \ Form \ Form的实例,没有给出,调用   /用户/ MacBook Pro的/桌面/ Projets   第834行的Web / Emirates / app / cache / dev / appDevDebugProjectContainer.php   和定义

我刚刚编写了我的service.yml:

services:
    flight_form:
        factory_service: form.factory
        factory_method: createNamed
        class: Symfony\Component\Form\Form
        arguments:
            - flight
            - flight_form

    flight_type:
        class: Test\FrontBundle\Form\Type\FlightType
        tags:
            - { name: form.type, alias: flight_form }

    flight_handler:
        class: Test\FrontBundle\Form\Handler\FlightHandler
        argument: [@flight_form, @request]
        scope: request
  

FlightController.php

        public function createAction(Request $request) {


            $formHandler = $this->get("flight_handler");
            $form = $formHandler->getForm();

            if ($formHandler->process()) {
                $em = $this->getDoctrine()->getManager();
                $em->persist($form->getData());
                $em->flush();

                return $this->redirect($this->generateUrl("test_front_flight_list"));
            }

            return $this->render('TestFrontBundle:Flight:create.html.twig', array('form' => $form->createView()));

        }
    }
  

FlightHandler.php

(...)

class FlightHandler {

    protected $form;
    protected $request;

    public function __construct(Form $form, Request $request) {
        $this->form = $form;
        $this->request = $request;
    }

    public function getForm() {
        return $this->form;
    }

    public function process() {

        $this->form->handleRequest($this->request);

        if ($this->request->isMethod("POST") && $this->form->isValid()) {
            return true;
        }
        return false;
    }

}
  

FlightType.php

public function setDefaultOptions(OptionsResolverInterface $resolver) {
    /** @var OptionResolver $resolver */
    $this->configureOptions($resolver);
}

public function configureOptions(OptionsResolver $resolver){
    $resolver->setDefaults(array(
        "data_class" => 'Test\FrontBundle\Entity\Flight'
    ));

1 个答案:

答案 0 :(得分:0)

没关系。在我的service.yml中,最后,#34;参数"必须是"参数"