Произошла ошибка при разрешении параметров формы "Symfony \ Component \ Form \ Extension \ Core \ Type \ PasswordType": параметры "0", "1" не существуют - PullRequest
0 голосов
/ 14 июля 2020

Я только начал изучать symfony framework, и у меня возникла ошибка.

Произошла ошибка при разрешении параметров формы «Symfony \ Component \ Form \ Extension \ Core \ Type \ PasswordType »: варианты« 0 »,« 1 »не существуют. Определенные параметры: действие, allow_extra_fields, allow_file_upload, always_empty, attr, attr_translation_parameters, auto_initialize, block_name, block_prefix, by_reference, plain, constraints. "," csrf_field_name "," csrf_message "," csrf_protection "," csrf_token_id "," csrf_token_manager "," data "," data_class "," disabled "," empty_data "," error_bubbling ",me" extra_mapping " «help», «help_attr», «help_ html», «help_translation_parameters», «inherit_data», «invalid_message», «invalid_message_parameters», «is_empty_callback», «label», «label_attr», «label_format», «label_ html "," label_translation_parameters "," mapped "," method "," post_max_size_message "," property_path "," required "," row_attr "," translation_domain "," trim "," upload_max_size_message "," validation_groups ".

Я даже нигде не ставил 0 или 1. Ошибка возникает при попытке посетить https://127.0.0.1: 8000 / регистр . Мой контроллер регистрации кода -

    <?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Routing\Annotation\Route;

class RegistrationController extends AbstractController
{
    /**
     * @Route("/register", name="register")
     */
    public function register()
    {

        $form = $this->createFormBuilder()
            ->add('username')
            ->add('password', RepeatedType::class,[
                'type' => PasswordType::class,
                'required' => true,
                'first_options' => ['label','Password'],
                'second_options' => ['label','Confirm Password']
            ])
            ->getForm();
        return $this->render('registration/index.html.twig', [
            'form' => $form->createView()
        ]);
    }
}

. Я следил за symfony учебником на YouTube, и он не получает сообщение об ошибке. Что я могу сделать? Спасибо

Изменить У меня была ошибка в 'first_options' и 'second_options' Правильный путь был 'first_options' => ['label' => 'Password'], 'second_options' = > ['label' => 'Подтвердите пароль']

1 Ответ

0 голосов
/ 04 августа 2020

Вы должны сделать так:

        $form = $this->createFormBuilder()
        ->add('username', TextType::class)
        ->add('password', RepeatedType::class, [
            'type' => PasswordType::class,
            'invalid_message' => 'The password fields must match.',
            'options' => ['attr' => ['class' => 'password-field']],
            'required' => true,
            'first_options'  => ['label' => 'Password'],
            'second_options' => ['label' => 'Confirm Password'],
        ])
        ->getForm();

и в поле зрения:

    {{ form_start(form) }}
        {{ form_row(form.username) }}
        {{ form_row(form.password.first) }}
        {{ form_row(form.password.second) }}
        <button type="submit">Register!</button>
    {{ form_end(form) }}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...