Symfony 3.3 CraueFormFlowBundle Request_stack 为空

Symfony 3.3 CraueFormFlowBundle Request_stack is empty

我对这个网站的第一个问题有点难以描述。 我对 Symfony 很陌生,从 3.2 开始,最近更新到 3.3.5(不确定是否与问题相关)。 我尝试使用 CraueFormFlowBundle(多步表单包)但无法使其正常工作。 问题是尝试访问流程会导致异常:

Error: Call to a member function getCurrentRequest() on null

Symfony\Component\Debug\Exception\ FatalErrorException
in vendor/craue/formflow-bundle/Form/FormFlow.php (line 191)

第 191 行显示:$currentRequest = $this->requestStack->getCurrentRequest();

修改 FormFlow.php with dump 行显示 $this->requestStack 为空。 我对这个包的了解不够,不知道从哪里开始寻找问题。

流程定义基于位置示例:

namespace EngineeringBundle\Form;

use Craue\FormFlowBundle\Form\FormFlow;
use Craue\FormFlowBundle\Form\FormFlowInterface;

class SelectExaminationFlow extends FormFlow
{

    /**
     * {@inheritDoc}
     */
    protected function loadStepsConfig()
    {
        dump("loadStepsConfig");
        return array(
            array(
                'label' => 'engineering.discipline',
                'form_type' => new SelectExaminationStep1Form(),
            ),
            array(
                'label' => 'engineering.date',
                'form_type' => new SelectExaminationStep2Form(),
                        'skip' => function($estimatedCurrentStepNumber, FormFlowInterface $flow) {
                            return $estimatedCurrentStepNumber > 1 && !$flow->getFormData()->canHaveRegion();
                        },
            ),
            array(
                'label' => 'confirmation',
            ),
        );
    }

表单定义也很简单,没有问题:

class SelectExaminationStep1Form extends AbstractType 
{
    public function buildForm(FormBuilderInterface $builder, array $options) 
  {
    dump("buildForm");
        $builder
      ->add('id', HiddenType::class)
      ->add('discipline', EntityType::class, array(
              'class' => 'EngineeringBundle:Discipline',
              'choice_label' => 'disciplineName',
              'label' => 'engineering.discipline.label'
              )
           );
    }

    public function getName() {
        return $this->getBlockPrefix();
    }

    public function getBlockPrefix() {
        return 'createEngineeringStep1';
    }

}

services.yml:

EngineeringBundle\Form\SelectExaminationFlow:
    parent: craue.form.flow
    autowire: false
    autoconfigure: false
    public: true

engineering.form_flow:
    alias: EngineeringBundle\Form\SelectExaminationFlow
    public: true

控制器:

/**
 * @Route("create", name="engineering_create")
 */
public function createAction()
{
    return $this->processFlow(new ExaminationDate(), $this->get('engineering.form_flow'));

}

提前致谢

塞巴斯蒂安

我遇到了同样的问题,通过向 vendor/craue/formflow-bundle/Form/FormFlow.php 添加构造函数解决了这个问题,内容如下:

public function __construct(RequestStack $requestStack, FormFactoryInterface $formFactory, DataManagerInterface $dataManager, EventDispatcherInterface $eventDispatcher) {
    $this->formFactory = $formFactory;
    $this->requestStack = $requestStack;
    $this->dataManager = $dataManager;
    $this->eventDispatcher = $eventDispatcher;
}

确保将它放在所有 setter 方法之后。问题似乎与 symfony 更新有关。