symfony 3错误

时间:2017-08-10 12:19:51

标签: symfony bundle

我尝试按照此链接安装并使用CraueFormFlowBundle

创建表单

CraueFormFlowBundle tutorial

我创建文件

/src/AppBundle/Form/InterventoFlow.php

 namespace AppBundle/Form;
    use Craue\FormFlowBundle\Form\FormFlow;
    use Craue\FormFlowBundle\Form\FormFlowInterface;

class InterventoFlow extends FormFlow {

    protected function loadStepsConfig() {
        return array(
            array(
                'label' => 'wheels',
                'form_type' => 'AppBundle\Form\InterventoForm',
            ),
            array(
                'label' => 'engine',
                'form_type' => 'AppBundle\Form\InterventoForm',
                'skip' => function($estimatedCurrentStepNumber, FormFlowInterface $flow) {
                    return $estimatedCurrentStepNumber > 1 && !$flow->getFormData()->canHaveEngine();
                },
            ),
            array(
                'label' => 'confirmation',
            ),
        );
    }

}

创建后

/src/AppBundle/Form/InterventoForm.php


<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 namespace AppBundle/Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class InterventoForm extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        switch ($options['flow_step']) {
            case 1:
                $validValues = array(2, 4);
                $builder->add('numberOfWheels', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
                    'choices' => array_combine($validValues, $validValues),
                    'placeholder' => '',
                ));
                break;
            case 2:
                // This form type is not defined in the example.
                $builder->add('engine', 'TextType', array(
                    'placeholder' => 'prova',
                ));
                break;
        }
    }

    public function getBlockPrefix() {
        return 'createIntervento';
    }

}

创建服务后

services:
    app.form.InterventoFlow:
        class: AppBundle\Form\InterventoFlow
        parent: craue.form.flow

和控制器

public function interventoAction(Request $request)
{
    $formData = new Validate(); // Your form data class. Has to be an object, won't work properly with an array.

$flow = $this->get('AppBundle.form.InterventoFlow'); // 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('home')); // redirect when done
    }
}


    return $this->render('interventi/intervento.html.twig', array(
               'form' => $form->createView(),
    'flow' => $flow,
    ));
}

和我的枝条文件

{% extends 'base.html.twig' %}

{% block body %}  
    <div>
    Steps:
    {% include '@CraueFormFlow/FormFlow/stepList.html.twig' %}
</div>
{{ form_start(form) }}
    {{ form_errors(form) }}

    {% if flow.getCurrentStepNumber() == 1 %}
        <div>
            When selecting four wheels you have to choose the engine in the next step.<br />
            {{ form_row(form.numberOfWheels) }}
        </div>
    {% endif %}

    {{ form_rest(form) }}

    {% include '@CraueFormFlow/FormFlow/buttons.html.twig' %}
{{ form_end(form) }}
{% endblock %}

{% stylesheets '@CraueFormFlowBundle/Resources/assets/css/buttons.css' %}
    <link type="text/css" rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

总是给我错误

服务“app.form.intervento”上的属性“autowire”在设置“parent”时无法从“_defaults”继承。将您的子定义移动到单独的文件或在C:\ xampp \ htdocs \ Myprject \ app / config \ services.yml中显式定义此属性(从“C:\ xampp \ htdocs \ Myprject \ app / config \”导入config.yml“)。

如果我发表评论

parent:craue.form.flow

您已请求不存在的服务“app.form.interventoFlow”。

1 个答案:

答案 0 :(得分:0)

尝试从service.yml文件中删除_defaults部分。