Не удалось загрузить тип "acme_user_registration" fosuserbundle
-
21-12-2019 - |
Вопрос
Использование инструкций по умолчанию здесь:
https://github.com/friendsofsymfony/fosuserbundle/ Blob / Master / Resources / Doc / index.md
Чтобы настроить пользовательское «имя» поле в моей регистрационной форме работает отлично.
Я хочу два поля для имени. Один для имени и другого для фамилии. Поэтому сначала я просто хотел переопределить поле имени на имя. Изменяя сущность на имя имени, вызывает эту ошибку:
Could not load type "acme_user_registration"
.
Почему это взорвется, когда я просто изменил заголовок столбца? Я также добавил Getter / Setters. Я думаю, что это проблема с Services.xml, но я не знаю, как сервисы работают с настройками YML и Builder Builder.
user.php
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your name.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=3,
* max="255",
* minMessage="The name is too short.",
* maxMessage="The name is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $firstname;
public function __construct()
{
parent::__construct();
// your own logic
}
.
<Сильные> Регистрация FormType.php
<?php
namespace MACP\CmsBundle\Form\Type;
use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
// add your custom field
$builder->add('firstname');
}
public function getFirstname()
{
return 'acme_user_registration';
}
}
.
<Сильные> услуги .xml
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="acme_user.registration.form.type" class="MACP\CmsBundle\Form\Type\RegistrationFormType">
<tag firstname="form.type" alias="acme_user_registration" />
<argument>%fos_user.model.user.class%</argument>
</service>
</services>
</container>
.
<Сильные> config.yml
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: MACP\CmsBundle\Entity\User
registration:
form:
type: acme_user_registration
. Решение
Пожалуйста, попробуйте изменить метод:
public function getFirstname()
{
return 'acme_user_registration';
}
.
to:
public function getName()
{
return 'acme_user_registration';
}
.
Этот метод скажет вам, как именно эта форма называется.И тогда вы используете это имя в конфигурации.Остальные выглядят просто для меня, но мы попробуем.