从 FOSUserBundle 扩展的用户导致 Easyadmin 列表偏移处的 unserialize() 错误
User extended from FOSUserBundle causes unserialize() Error at offset at Easyadmin list
我使用 1.16.10 版本的 EasyAdminBundle。
我创建了用户实体,从 FOSUser 的模型中扩展了它(如文档中所示)并将其添加到 easyadmin 配置文件中。结果我得到了以下错误:
An exception has been thrown during the rendering of a template ("Notice: unserialize(): Error at offset 0 of 34 bytes").
堆栈跟踪的完整描述:
CRITICAL - Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("Notice: unserialize(): Error at offset 0 of 34 bytes")." at \vendor\javiereguiluz\easyadmin-bundle\Resources\views\default\list.html.twig line 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' } } }`
我做错了什么?是什么导致了这个错误?我该如何解决?
FOS UserBundle 的基础 User-model 包含序列化和反序列化,将模型的属性输出为数组,然后对其调用序列化并再次从该数组反序列化和设置自身。
我的假设是,您要么重命名了其中一些属性,要么尝试加载一个包含反序列化无法处理的数据的模型,例如因为数据在某个时候被截断了或者类似的奇怪的事情。您可能想要清除旧会话,因为据我所知 serialize/unserialize 仅用于在会话中存储数据,或者您可能希望通过查看它试图反序列化的序列化数据来开始调试。
我使用 1.16.10 版本的 EasyAdminBundle。 我创建了用户实体,从 FOSUser 的模型中扩展了它(如文档中所示)并将其添加到 easyadmin 配置文件中。结果我得到了以下错误:
An exception has been thrown during the rendering of a template ("Notice: unserialize(): Error at offset 0 of 34 bytes").
堆栈跟踪的完整描述:
CRITICAL - Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("Notice: unserialize(): Error at offset 0 of 34 bytes")." at \vendor\javiereguiluz\easyadmin-bundle\Resources\views\default\list.html.twig line 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' } } }`
我做错了什么?是什么导致了这个错误?我该如何解决?
FOS UserBundle 的基础 User-model 包含序列化和反序列化,将模型的属性输出为数组,然后对其调用序列化并再次从该数组反序列化和设置自身。
我的假设是,您要么重命名了其中一些属性,要么尝试加载一个包含反序列化无法处理的数据的模型,例如因为数据在某个时候被截断了或者类似的奇怪的事情。您可能想要清除旧会话,因为据我所知 serialize/unserialize 仅用于在会话中存储数据,或者您可能希望通过查看它试图反序列化的序列化数据来开始调试。