传递给函数的参数不是某个类错误的实例 [英] Argument passed to function is not an instance of some class error
问题描述
尝试从控制器调用方法时遇到此错误:
I'm having this error when try to call a method from my controller:
可捕获的致命错误:参数 2 传递给RPNIBundle\Controller\CraueController::processFlow() 必须是一个RPNIBundle\Controller\FormFlowInterface 的实例,RPNIBundle\Form\RegistroProductoFlow 给定,调用/var/www/html/src/RPNIBundle/Controller/CraueController.php 第 21 行并定义在/var/www/html/src/RPNIBundle/Controller/CraueController.php 第 29 行
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
推荐答案
您似乎忘记了控制器类顶部的 use 语句?
It appears that you forgot a use statement at the top of your controller class?
use Craue\FormFlowBundle\Form\FormFlowInterface;
那个函数 (processFlow
) 不属于控制器 btw.控制器应该接受一个 Request
并返回一个 Response
.:)
That function (processFlow
) doesn't belong in a controller btw. Controllers should take a Request
and return a Response
. :)
这篇关于传递给函数的参数不是某个类错误的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!