尝试从我的控制器调用方法时遇到此错误:
可捕获的致命错误:参数2传递给 RPNIBundle \ Controller \ CraueController :: processFlow()必须是 RPNIBundle \ Controller \ FormFlowInterface的实例,实例 给出的RPNIBundle \ Form \ RegistroProductoFlow,调用 第21行的/var/www/html/src/RPNIBundle/Controller/CraueController.php 并定义于 /var/www/html/src/RPNIBundle/Controller/CraueController.php第29行
我无法得到我犯错的地方所以我可以使用一点帮助,这就是我所做的:
的src / RPNIBundle /控制器/ CraueController.php
class CraueController extends Controller
{
/**
* @Route("/rpni/registro/craue", name="registro-craue")
* @Template()
*/
public function registroSolicitudProductoAction()
{
$flow = $this->get('registrarProducto.form.flow');
$flow->setAllowDynamicStepNavigation(true);
// @todo add this to use statement
return $this->processFlow(new \ComunBundle\Entity\Producto(), $flow);
}
protected function processFlow($formData, FormFlowInterface $flow)
{
$flow->bind($formData);
$form = $submittedForm = $flow->createForm();
if ($flow->isValid($submittedForm)) {
$flow->saveCurrentStepData($submittedForm);
if ($flow->nextStep()) {
$form = $flow->createForm();
} else {
$flow->reset();
return $this->redirect($this->generateUrl('_FormFlow_start'));
}
}
if ($flow->redirectAfterSubmit($submittedForm)) {
$request = $this->getRequest();
$params = $this->get('craue_formflow_util')->addRouteParameters(array_merge($request->query->all(), $request->attributes->get('_route_params')), $flow);
return $this->redirect($this->generateUrl($request->attributes->get('_route'), $params));
}
return array(
'form' => $form->createView(),
'flow' => $flow,
'formData' => $formData,
);
}
}
的src / RPNIBundle /窗体/ RegistroProductoFlow.php
class RegistroProductoFlow extends FormFlow
{
/**
* {@inheritDoc}
*/
public function getName()
{
return 'registroSolicitudProducto';
}
/**
* {@inheritDoc}
*/
protected function loadStepsConfig()
{
return array(
array(
'label' => 'Datos Solicitud',
'type' => new RegistroProductoFormType(),
),
array(
'label' => 'Datos Producto',
'type' => $this->formType
),
array(
'label' => 'Pagos',
'type' => $this->formType
),
array(
'label' => 'Confirmación',
),
);
}
/**
* {@inheritDoc}
*/
public function getFormOptions($step, array $options = array())
{
$options = parent::getFormOptions($step, $options);
$options['cascade_validation'] = true;
return $options;
}
}
的src / RPNIBundle /窗体/类型/ RegistroProductoFormType.php
class RegistroProductoFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('tipo_tramite', 'entity', array(
'class' => 'ComunBundle:TipoTramite',
'property' => 'nombre',
'required' => TRUE,
'label' => "Tipo de Trámite",
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('q')
->where('q.activo = :valorActivo')
->setParameter('valorActivo', true);
}
))
->add('oficina_regional', 'entity', array(
'mapped' => FALSE,
'class' => 'ComunBundle:OficinaRegional',
'property' => 'nombre',
'required' => TRUE,
'label' => "Oficina Regional",
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('q')
->where('q.activo = :valorActivo')
->setParameter('valorActivo', true);
}
));
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'registroProducto';
}
}
的src / RPNIBundle /资源/配置/ services.yml
services:
registrarProducto.form:
class: RPNIBundle\Form\Type\RegistroProductoFormType
tags:
- { name: form.type, alias: registrarProducto }
registrarProducto.form.flow:
class: RPNIBundle\Form\RegistroProductoFlow
parent: craue.form.flow
scope: request
有人可以给我一些帮助吗?我正在挖掘代码,但我找不到问题
答案 0 :(得分:1)
您似乎忘记了控制器类顶部的use语句?
use Craue\FormFlowBundle\Form\FormFlowInterface;
该功能(processFlow
)并不属于控制器btw。控制器应该使用Request
并返回Response
。 :)