我有这个用户实体从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()", " __得到()"在课堂上存在并具有公共访问权限 " PDOneBundle \实体\用户"
为什么呢?不应该从BaseUser扩展这些方法吗?为什么会出错?
答案 0 :(得分:2)
看起来财产expiresAt
有一个吸气剂:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Model/User.php
如果User
需要,我猜您可以在扩展的EasyAdminBundle
课程中轻松添加自己的getter。
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-configuration