Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在FOSUserBundle中添加注册表另一字段Symfony 2.7_Php_Symfony_Doctrine - Fatal编程技术网

Php 如何在FOSUserBundle中添加注册表另一字段Symfony 2.7

Php 如何在FOSUserBundle中添加注册表另一字段Symfony 2.7,php,symfony,doctrine,Php,Symfony,Doctrine,如何在注册表上添加字段?我这样做: \\src\UserBundle\Form\Type\RegistrationFormType.php <?php namespace UserBundle\Form\Type; //use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use FOS\UserBundle\Form\T

如何在注册表上添加字段?我这样做:

\\src\UserBundle\Form\Type\RegistrationFormType.php
    <?php 
    namespace UserBundle\Form\Type;

    //use Symfony\Component\Form\AbstractType;
    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);
            $builder->add('realname');
        }

        public function getParent()
        {
            return 'fos_user_registration';
        }

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

\\src\UserBundle\Resources\config 
services:
     app_user.registration.form.type:
        class: UserBundle\Form\Type\RegistrationFormType
        arguments: [%fos_user.model.user.class%]
        tags:
        - { name: form.type, alias: app_user_registration }

\\src\UserBundle\Entity\User.php
namespace UserBundle\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="web_user")
 */
class User extends BaseUser
{
    /**
     * @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 $realname;



    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set realname
     *
     * @param string $realname
     * @return User
     */
    public function setRealname($realname)
    {
        $this->realname = $realname;

        return $this;
    }

    /**
     * Get realname
     *
     * @return string 
     */
    public function getRealname()
    {
        return $this->realname;
    }
}

\\src\UserBundle\Resources\config\services.yml
services:
     app_user.registration.form.type:
        class: UserBundle\Form\Type\RegistrationFormType
        arguments: [%fos_user.model.user.class%]
        tags:
        - { name: form.type, alias: app_user_registration }
\\src\UserBundle\Form\Type\RegistrationFormType.php
身份证件
}
/**
*设置实名
*
*@param string$realname
*@返回用户
*/
公共函数setRealname($realname)
{
$this->realname=$realname;
退还$this;
}
/**
*获取真实名称
*
*@返回字符串
*/
公共函数getRealname()
{
返回$this->realname;
}
}
\\src\UserBundle\Resources\config\services.yml
服务:
app_user.registration.form.type:
类:UserBundle\Form\Type\RegistrationFormType
参数:[%fos\u user.model.user.class%]
标签:
-{name:form.type,别名:app\u user\u registration}
我不明白遗漏了什么 结果是一个错误: 无法加载类型“应用程序用户注册” 请帮帮我!!! 我想服务没有发现我有同样的问题。(实际上,我是通过谷歌搜索我们两人的错误找到你的帖子的) 我刚刚开始学习和玩弄symfony,所以请对此持保留态度

在config.yml中尝试以下操作:

  • 删除您编写的服务,然后重试
  • 替换为:
    
    fos_用户:
    db_驱动程序:orm
    防火墙名称:main
    用户\u类:UserBundle\Entity\user
    注册:
    表格:
    类型:应用程序\用户\注册