我使用 1.16.10 版本的 EasyAdminBundle。我创建了用户实体,从 FOSUser 的模型中扩展它(如文档中所示)并将其添加到 easyadmin 配置文件中。结果我得到了以下错误:
在渲染模板期间引发了异常(“注意:unserialize():34 字节偏移量 0 处出错”)。
堆栈跟踪的完整描述:
CRITICAL - 未捕获的 PHP 异常 Twig_Error_Runtime:“在渲染模板期间引发了异常(“注意:反序列化():34 字节偏移量 0 处出错”)。在 \vendor\javiereguiluz\easyadmin-bundle\Resources\views\default\list.html.twig 第 132 行
所以,我的实体的代码:
namespace BackofficeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* AclUser
*
* @ORM\Entity(repositoryClass="BackofficeBundle\Repository\AclUserRepository")
* @ORM\Table(name="Acl_User")
*/
class AclUser extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="ip_address", type="string", length=255, nullable=true)
*/
private $ipAddress;
/**
* @var boolean
*
* @ORM\Column(name="locked", type="boolean")
*/
private $locked = false;
/**
* @ORM\Column(name="expired", type="boolean")
*/
private $expired = false;
/**
* @ORM\Column(name="expires_at", type="datetime", nullable=true)
*/
private $expiresAt;
/**
* @ORM\Column(name="credentials_expired", type="boolean", nullable=true)
*/
private $credentialsExpired;
/**
* @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true)
*/
private $credentialsExpireAt;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private $createdAt;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="update")
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
private $updatedAt;
public function __construct()
{
parent::__construct();
$this->createdAt = new \DateTime('now');
}
/** generated getters and setters **/
}`
我的 user.yml 文件,导入到 config.yml:
easy_admin:
entities:
User:
class: BackofficeBundle\Entity\AclUser
list:
fields:
- id
- username
- email
- enabled
- lastLogin
- { property: roles, type: json_array, template: '@BackofficeBundle/Resources/views/fields/role.html.twig' }
form:
fields:
- username
- email
- enabled
- lastLogin
- { property: 'plainPassword', type: 'text', type_options: { required: false } }
- { property: 'roles', type: 'choice', type_options: { multiple: true, choices: { 'ROLE_APP_SUPER_ADMIN' : 'ROLE_APP_ADMIN', 'ROLE_APP_ADMIN' : 'ROLE_APP_USER', 'ROLE_APP_USER' : 'ROLE_USER' } } }`
我做错什么了?是什么导致了这个错误?我该如何解决?