0

我有这个用户实体从 BaseUser 扩展:

namespace PDOneBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use PDOneBundle\Classes\Form\Validator\Constraints as GdcaAssert;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;

/**
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 * @ORM\Table(name="fos_user")
 * @ORM\Entity(repositoryClass="PDOneBundle\Entity\Repository\UserRepository")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
 */
class User extends BaseUser
{
    /*
     * Hook timestampable behavior
     * updates createdAt, updatedAt fields
     */
    use TimestampableEntity;

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var int
     *
     * @Assert\NotBlank()
     *
     * @ORM\ManyToOne(targetEntity="Company", inversedBy="users", cascade={"persist"})
     * @ORM\JoinColumn(name="company_id", referencedColumnName="ID")
     */
    protected $company;

    /**
     * @ORM\ManyToMany(targetEntity="Company", mappedBy="admins", cascade={"persist"})
     */
    protected $companies;

    /**
     * @ORM\ManyToMany(targetEntity="Project", mappedBy="admins", cascade={"persist"})
     */
    protected $projects;

    // methods goes here
}

我也在使用 EasyAdminBundle,每当我尝试从 EasyAdmin 添加新用户时,都会出现以下错误:

属性“expiresAt”和方法之一“getExpiresAt()”、“expiresAt()”、“isExpiresAt()”、“hasExpiresAt()”、“__get()”都不存在并且在类“PDOneBundle\”中具有公共访问权限实体\用户”。

为什么?这些方法不应该是从 BaseUser 扩展而来的吗?为什么会出错?

4

1 回答 1

2

看起来没有属性的吸气剂expiresAthttps ://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Model/User.php 我想如果需要,您可以轻松地在扩展User类 中添加自己的吸气剂EasyAdminBundle.

class User extends BaseUser
{
    // ...
    public function getExpiresAt() {
        return $this->expiresAt;
    }
    // ...
}

看起来您还可以定义哪些属性EasyAdminBundle控制:https ://github.com/javiereguiluz/EasyAdminBundle/blob/v1.2.1/Resources/doc/11-configuration-reference.md#advanced-configuration-with-custom-field-配置

于 2015-04-20T16:18:18.247 回答