我使用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,
));
}
答案 0 :(得分: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',
);
}
}
希望这个帮助