gpt4 book ai didi

php - 尝试将字段添加到注册表单时无法加载类型 "app_user_registration"

转载 作者:行者123 更新时间:2023-12-04 02:07:28 24 4
gpt4 key购买 nike

我正在使用 Doctrine 和 FOSBundle 2.0 在 Symfony3 中开发一个应用程序。

我一直在尝试在我的注册栏中添加两个字段 firstNamelastName

I have found this tutorial on how do do precisely what I'm hoping ,不幸的是,在前几个步骤之后(在处理之前)我意识到我收到了这个错误:

Could not load type "app_user_registration"

我使用的代码是从网站上完全复制的,唯一的区别是我的类看起来像这样

<?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;

当有一个名为..."name"的变量时会发生同样的效果


我花了最后几个小时试图找出答案。这是我尝试过的:

其他一切都显示我的输出代码作为问题的答案

谁能帮助一个可怜的人?

作为补充,这是我的其他文件:

//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';
}
}

最佳答案

你应该改用这个教程(2.0.master): http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html

您正在使用教程“1.3.x 版本”。

对于 Symfony3,您必须进行以下更改:

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

关于php - 尝试将字段添加到注册表单时无法加载类型 "app_user_registration",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42035679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com