类 '...EntityUser' 没有方法'getGenderList'



我正在使用Sonata Admin bundle作为我网站的后端。

我的用户表在我的数据库中是这样的:

id (PK)
username
email
password
salt
last_login
created_at
company_id (FK)

我的用户实体如下所示:

<?php
namespace MyBundleEntity;
use FOSUserBundleEntityUser as BaseUser;
//use SonataUserBundleEntityBaseUser as BaseUser;
use DoctrineORMMapping as ORM;
/**
 * User
 *
 * @ORMTable(name="user", indexes={@ORMIndex(name="fk_user_company1_idx", columns={"company_id"})})
 * @ORMEntity
 */
class User extends BaseUser
{
    /**
     * @var DateTime
     *
     * @ORMColumn(name="created_at", type="datetime", nullable=true)
     */
    protected $createdAt;
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    protected $id;
    /**
     * @var MyBundleEntityCompany
     *
     * @ORMManyToOne(targetEntity="MyBundleEntityCompany")
     * @ORMJoinColumns({
     *   @ORMJoinColumn(name="company_id", referencedColumnName="id")
     * })
     */
    protected $company;
    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
    /**
     * Set username
     *
     * @param string $username
     * @return User
     */
    public function setUsername($username)
    {
        $this->username = $username;
        return $this;
    }
    /**
     * Get username
     *
     * @return string 
     */
    public function getUsername()
    {
        return $this->username;
    }
    /**
     * Set email
     *
     * @param string $email
     * @return User
     */
    public function setEmail($email)
    {
        $this->email = $email;
        return $this;
    }
    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }
    /**
     * Set password
     *
     * @param string $password
     * @return User
     */
    public function setPassword($password)
    {
        $this->password = $password;
        return $this;
    }
    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }
    /**
     * Set salt
     *
     * @param string $salt
     * @return User
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;
        return $this;
    }
    /**
     * Get salt
     *
     * @return string 
     */
    public function getSalt()
    {
        return $this->salt;
    }
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set company
     *
     * @param MyBundleEntityCompany $company
     * @return User
     */
    public function setCompany(MyBundleEntityCompany $company = null)
    {
        $this->company = $company;
        return $this;
    }
    /**
     * Get company
     *
     * @return MyBundleEntityCompany 
     */
    public function getCompany()
    {
        return $this->company;
    }
}

现在,当我转到"编辑帐户"页面时,我得到以下错误:

Warning: call_user_func() expects parameter 1 to be a valid callback, class 'MyBundleEntityUser' does not have a method 'getGenderList'

我没有性别在我的用户表在我的数据库。我该如何解决这个问题?

更新:

当我将use FOSUserBundleEntityUser as BaseUser;改为use SonataUserBundleEntityBaseUser as BaseUser;时。然后我得到以下错误:

在执行'SELECT t0 '时发生异常。username AS username1, t0。username_canonical AS username_canonical2, 0。email AS email3, to 0。email_canonical AS email_canonical4, 0。enabled AS enabled5, 0。盐;盐;password AS password7, 0。last_login AS last_login8, 0。locked AS lockked9, 0。AS expired AS已过期。expires_at AS expires_at11, 0。confirmation_token AS confirmation_token12, t0。password_requested_at AS password_requested_at13, t0。roles AS roles14, 0。AS credentials_expired15, 0。credentials_expire_at AS credentials_expire_at 16,0。created_at = created_at17, 0。updated_at AS updated_at18, 0。date_of_birth = date_of_birth19, 0。第一个名字是第一个名字。lastname AS lastname21, to 0。网站AS网站;传记;传记;gender AS gender24, 10。locale AS locale25, 0。timezone AS timezone26, 0。电话号码是27,10。facebook_uid = facebook_uid28, 0。facebook_name = facebook_name29, 0。facebook_data为facebook_data30,0。twitter_uid AS twitter_uid31, 0。twitter_name AS twitter_name32, t0。twitter_data = twitter_data33, 0。gplus_uid AS gplus_uid34, t0。gplus_name AS gplus_name35, t0。gplus_data = gplus_data36, 0。token AS token37, to0。two_step_code作为two_step_code38, t0。id AS id39, t0.company_id AS company_id40Id = ?LIMIT 1'与参数1:

SQLSTATE[42S22]: Column not found: 1054未知列't0.updated_at'In 'field list'

我该如何解决这个问题?

你的User类从FOSUserBundle扩展而不是SonataUserBundle。你必须改变它:

//use FOSUserBundleEntityUser as BaseUser;
use SonataUserBundleEntityBaseUser as BaseUser;

检查https://github.com/sonata-project/SonataUserBundle/issues/459

编辑:如果你不想使用这个类(其中有很多无用的字段),那么你必须为你的User实体创建你自己的管理类。本页有一个完整的指南:http://m2mdas.github.io/blog/2013/11/18/integrate-fosuserbundle-and-sonatauserbundle-easily/

更新后更新:在更改实体扩展的类之后,必须更新数据库模式以匹配模型:

php app/console doctrine:schema:update --force

相关内容

  • 没有找到相关文章

最新更新