craue / CraueFormFlowBundle

Multi-step forms for your Symfony project.
MIT License
736 stars 118 forks source link

Error when using form data class who is not an entity > look for ID #375

Closed chrisVdd closed 3 years ago

chrisVdd commented 3 years ago

Hi guys,

I'm trying to use CraueFormFlowBundle because I need to create a quite complex form, with multiple steps. Here is my workflow:

The ultimate goal is to be able to import some data in DB.

Here is what I did:

`// CONTROLLER $formData = new UserImportModel(); $importUsersFlow->bind($formData);

    /** @var FormInterface $form */
    $form = $importUsersFlow->createForm();

    if ($importUsersFlow->isValid($form)) {

        $importUsersFlow->saveCurrentStepData($form);

        if ($importUsersFlow->nextStep()) {

            $form = $importUsersFlow->createForm();

        } else {

            $entityManager = $this->getDoctrine()->getManager();
            $entityManager->persist($formData);

            $entityManager->flush();

            $importUsersFlow->reset();

            return $this->redirect($this->generateUrl('import-completed'));
        }
    }`

`// UserImportModel class UserImportModel { public $excelFile;

/** @var int */
public $duplicateEmails;

/**
 * @return int
 */
public function getDuplicateEmails(): int
{
    return $this->duplicateEmails;
}

/**
 * @param int $duplicateEmails
 */
public function setDuplicateEmails(int $duplicateEmails): void
{
    $this->duplicateEmails = $duplicateEmails;
}

}`

`// MY FLOW class ImportUsersFlow extends FormFlow {

/**
 * @return array|string[]
 */
protected function loadStepsConfig()
{
    return
        [
            [
                'label'     => 'Excel file',
                'form_type' => ImportExcelType::class,
            ],
            [
                'label'     => 'Some questions',
                'form_type' => UserImportQuestionForm::class,
            ],
    ];
}

}`

My file is uploaded, but just after the UserImportQuestionForm (step2) I have this error:

Can't get a way to read the property "id" in class "App\Entity\Model\UserImportModel".

I do not have a property ID in UserImportModel, I worked kind of what you did in the demo, here: DEMO UPLOAD

Can somebody can maybe help to understand why I get this ?