Reputation: 18660
I'm having this error when try to call a method from my controller:
Catchable Fatal Error: Argument 2 passed to RPNIBundle\Controller\CraueController::processFlow() must be an instance of RPNIBundle\Controller\FormFlowInterface, instance of RPNIBundle\Form\RegistroProductoFlow given, called in /var/www/html/src/RPNIBundle/Controller/CraueController.php on line 21 and defined in /var/www/html/src/RPNIBundle/Controller/CraueController.php line 29
I can't get where I am making the mistake so I could use a little help, this is what I have done:
src/RPNIBundle/Controller/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/Form/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/Form/Type/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/Resources/config/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
Can any give me some help? I'm digging through the code but I can not find the problem
Upvotes: 0
Views: 150
Reputation: 2811
It appears that you forgot a use statement at the top of your controller class?
use Craue\FormFlowBundle\Form\FormFlowInterface;
That function (processFlow
) doesn't belong in a controller btw. Controllers should take a Request
and return a Response
. :)
Upvotes: 1