将列添加到 FosUserBundle 表和表单 Symfony 2.8



我正在使用Symfony 2.8和FosuserBundle。我有一个问题,我无法在我的实体中添加新属性。我的实体用户看起来像

    <?php
// src/AppBundle/Entity/User.php
namespace AppBundleEntity;
use FOSUserBundleEntityUser as BaseUser;
use DoctrineORMMapping as ORM;
/**
 * @ORMEntity
 * @ORMTable(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     * @ORMname
     * @ORMColumn(type="VARCHAR")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $name;
    /**
     * @ORMlastname
     * @ORMColumn(type="VARCHAR")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $lastname;
    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }
    public function setLastname($lastname)
    {
        $this->lastname = $lastname;
        return $this;
    }
}

,但我始终得到错误:" AnnotationException.php第54行中的AnnotationException:[语义错误]注释" @doctrine orm mapping name"在属性AppBundle Entity Entity user :: $ name不存在,或者无法自动加载。"

>

也许我的registrationformtype有所帮助,因为我也更改了它。

<?php
/*
 * This file is part of the FOSUserBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace FOSUserBundleFormType;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolverInterface;
class RegistrationFormType extends AbstractType
{
    private $class;
    /**
     * @param string $class The User class name
     */
    public function __construct($class)
    {
        $this->class = $class;
    }
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
            ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
            ->add('plainPassword', 'repeated', array(
                'type' => 'password',
                'options' => array('translation_domain' => 'FOSUserBundle'),
                'first_options' => array('label' => 'form.password'),
                'second_options' => array('label' => 'form.password_confirmation'),
                'invalid_message' => 'fos_user.password.mismatch',
            ))
            ->add('name')
            ->add('lastname')
        ;
    }
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => $this->class,
            'intention'  => 'registration',
        ));
    }
    public function getName()
    {
        return 'fos_user_registration';
    }
}

我在mysql中手动添加了字段名称和姓氏。

我忘了编辑哪些文件?

最好的问候,托马斯

我认为您应该更正以下内容:实体定义

namespace AppBundleEntity;
use FOSUserBundleEntityUser as BaseUser;
use DoctrineORMMapping as ORM;
/**
 * @ORMEntity
 * @ORMTable(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     *@var string
     *
     * @ORMColumn(name="name",type="string")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $name;
    /**
     * @var string
     *
     * @ORMColumn(name="lastname",type="string")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $lastname;
    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }
      public function getName()
    {
         return $this->name;
    }
    public function setLastname($lastname)
    {
        $this->lastname = $lastname;
        return $this;
    }
      public function getLastname()
    {

        return $this->lastname ;
    }
}

您也不需要编辑fosuserbundle formType,而是在捆绑中创建一个基于 user class> class的新FormType。

相关内容

  • 没有找到相关文章

最新更新