【问题标题】:Navigating CraueFormFlowBundle when editing existing entity编辑现有实体时导航 CraueFormFlowBundle
【发布时间】:2014-09-22 14:22:49
【问题描述】:

我使用CraueFormFlowBundle 创建了一个多页表单。使用此表单,我可以创建新实体对象或编辑现有实体对象。

然后我添加了设置

protected $allowDynamicStepNavigation = true;

允许在表单的页面中来回导航,但是当使用表单编辑现有对象时,我希望能够直接跳转到表单中的任何页面。这似乎不起作用 - 对象数据已加载,我可以反复按下一步,直到到达所需的页面。
使用 CraueFormFlowBundle 进行编辑时,有没有办法呈现页面导航?

我的模板包括:

{% include 'CraueFormFlowBundle:FormFlow:stepList.html.twig' %} 

创建导航。这是editAction:

    public function editDriverAction($id) {

    $em = $this->getDoctrine()->getManager();

    $formData = $em->getRepository('NewgtDriverBundle:NewgtDriver')->find($id);

    if (!$formData) {
        throw $this->createNotFoundException('Unable to find Driver.');
    }

    //$formData = new NewgtDriver(); // Your form data class. Has to be an object, won't work properly with an array.

    $flow = $this->get('newgtDriver.form.flow.createDriver'); // must match the flow's service id
    $flow->bind($formData);

    // form of the current step
    $form = $flow->createForm();
    if ($flow->isValid($form)) {
        $flow->saveCurrentStepData($form);

        if ($flow->nextStep()) {
            // form for the next step
            $form = $flow->createForm();
        } else {
            // flow finished
            $em = $this->getDoctrine()->getManager();
            $em->persist($formData);
            $em->flush();

            $flow->reset(); // remove step data from the session

            return $this->redirect($this->generateUrl('driver')); // redirect when done
        }
    }

    return $this->render('NewgtDriverBundle:Driver:new.html.twig', array(
        'form' => $form->createView(),
        'flow' => $flow,
    ));
}

【问题讨论】:

    标签: forms symfony twig craueformflow


    【解决方案1】:

    In the source code我们看到流类必须重写方法loadStepDescriptions。

    我的 FromFlow 类是这样的:

    
    namespace MyBundle\Form\Proposal;
    
    use Craue\FormFlowBundle\Form\FormFlow;
    
    class ProposalFlow extends FormFlow {
    
        protected $maxSteps = 5;
    
        protected $allowDynamicStepNavigation = true;
    
        protected function loadStepDescriptions() {
            return array(
                'Name',
                'Contract',
                'Filter',
                'Alternative',
                'Summary',
            );
        }
    }
    

    希望有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-27
      • 2020-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-07
      • 2017-04-22
      • 1970-01-01
      相关资源
      最近更新 更多