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:
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';
}
}
You should use this tuorial instead (2.0.master): http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html
You are using tutorial "1.3.x version".
For Symfony3 you have to make this changes:
class RegistrationType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('name'); } public function getParent() { return 'FOS\UserBundle\Form\Type\RegistrationFormType'; } public function getBlockPrefix() { return 'app_user_registration'; } }
services: app.form.registration: class: AppBundle\Form\RegistrationType tags: - { name: form.type, alias: app_user_registration }
fos_user: # ... registration: form: type: AppBundle\Form\RegistrationType
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.