我使用CraueFormFlowBundle创建了一个多页表单。使用此表单,我可以创建一个新的实体对象或编辑一个现有的实体对象。
然后我添加了设置
protected $allowDynamicStepNavigation = true;
允许在表单的页面中来回导航,但是,当使用表单编辑现有对象时,我希望能够直接跳转到表单中的任何页面。这似乎不起作用-对象数据已加载,我可以重复按next,直到到达所需页面
在使用CraueFormFlowBundle进行编辑时,是否有方法呈现页面导航?
我的模板包括:
{% include 'CraueFormFlowBundle:FormFlow:stepList.html.twig' %}
以创建导航。这是编辑操作:
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,
));
}
在源代码中,我们看到流类必须重写方法loadStepDescriptions。
我的FromFlow类类似于:
namespace MyBundleFormProposal;
use CraueFormFlowBundleFormFormFlow;
class ProposalFlow extends FormFlow {
protected $maxSteps = 5;
protected $allowDynamicStepNavigation = true;
protected function loadStepDescriptions() {
return array(
'Name',
'Contract',
'Filter',
'Alternative',
'Summary',
);
}
}
希望这能帮助