Could not load type “app_user_registration” when attempting to add fields into registration form

111
February 04, 2017, at 12:20 PM

I'm working on a app in Symfony3 with Doctrine and the FOSBundle 2.0.

I have been trying to add two fields into my registration bar the firstName and the lastName.

I have found this tutorial on how do do precisely what I'm hoping, unfortunately after the first few steps (prior to handling) I realize I'm getting this error:

Could not load type "app_user_registration"

The code I'm using is exacly copied from the webiste, only difference is that my class looks like this

<?php
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    /** @ORM\Column(type="integer") */
    protected $carma;
    /**
     * @ORM\Column(type="string", length=255)
     *
     * @Assert\NotBlank(message="Please enter your first 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;
    /**
     * @ORM\Column(type="string", length=255)
     *
     * @Assert\NotBlank(message="Please enter your first 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 $lastName;

Same effect occurs when there is a variable named..."name"

I have spend the last few hours trying to figure out. There is what I have tried:

  • Using the 2.0-master version tutorial
  • The answer form here

Everything else showed my output code as the answer to the question.

Could anyone help a poor soul?

As an addition, here are my other files:

//config.yml
/*...*/
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: AppBundle\Entity\User
    registration:
        form:
            type: AppBundle\Form\RegistrationType
//services.yml
services:
    app.form.registration:
        class: AppBundle\Form\RegistrationType
        tags:
            - { name: form.type, alias: app_user_registration }
//RegistraionType.php
<?php
// src/AppBundle/Form/RegistrationType.php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('firstName');
    }
    public function getParent()
    {
        return 'fos_user_registration';
    }
    public function getName()
    {
        return $this->getBlockPrefix();
    }
    public function getBlockPrefix()
    {
        return 'app_user_registration';
    }
}
Answer 1

I suspect you have been trying to also follow the tutorials for extending the registration form. You most likely should have the following entry in your app/config/services.yml file:

app.form.registration:
    class: AppBundle\Form\RegistrationType
    tags:
        - { name: form.type, alias: app_user_registration }

Then in your src/AppBundle/Form/RegistrationType.php you should have the following function:

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

That is most likely where the error is coming from in your getBlockPrefix() method. Check your services.yml and compare to what I posted. I grabbed that from my own app which is working fine.

READ ALSO
&ldquo;OnClick&rdquo; Ajax function on &#39;&#39;IMAP to PHP page&#39;&#39;

“OnClick” Ajax function on ''IMAP to PHP page''

Everything works fine, but i need one more functionOn every newmail, in same line i need button "OWNER", so when user input his inicials in that field, field will be locked so anybody can know who own which mail

103
Should/Must I use PDO::PARAM_NULL when binding a value that is null?

Should/Must I use PDO::PARAM_NULL when binding a value that is null?

When preparing an SQL query using PDO, should/must I do

121
which data types- foreach

which data types- foreach

I have one little question:

84
csrf_exempt decorator not exempting

csrf_exempt decorator not exempting

I have a wordpress site (coded with PHP) that I am using to post data to a django viewI post with this code

112