質問

ここでのデフォルトの指示を使用して:

https://github.com/friendsofsymfony/fosuserbundle/ BLOB /マスター/リソース/ doc / index.md

私の登録フォームのカスタム「名前」フィールドを設定するためには、素晴らしい機能です。

名前の2つのフィールドが欲しいのですが。姓のためのものと他の名前のためのもの。だから最初に私はちょうど名前フィールドを最初の名前に上書きしたいと思いました。エンティティを最初の名前に変更すると、このエラーが発生します。

Could not load type "acme_user_registration"
.

単に列のタイトルを変更したときに爆発するのはなぜですか? IVEがゲッター/セッターを追加しました。私はそれがservices.xmlの問題であると思いますが、私はサービスがYML設定とフォームビルダーとの仕組みを知りません。

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
    } 
.

registrationFormType.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';
    }
}
.

services.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';
}
.

このメソッドは、このフォームがどれだけ正確に呼ばれているかを教えてください。その後、この名前を設定します。残りは私にとってちょうど元気に見えますが、試してみます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top