dongshan4518 2017-07-27 22:57
浏览 51
已采纳

从FOSUserBundle扩展的用户在Easyadmin列表中导致偏移时出现unserialize()错误

I use 1.16.10 version of EasyAdminBundle. I created User entity, extended it from FOSUser's model (as in documentation) and added it to easyadmin configuration file. As a result I got the following error:

An exception has been thrown during the rendering of a template ("Notice: unserialize(): Error at offset 0 of 34 bytes").

The full description from Stack trace:

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

So, the code of my entity:

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 **/
}`

My user.yml file, imported to 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' } } }`

What did I do wrong? What causes this error? How can I solve it?

  • 写回答

1条回答 默认 最新

  • dpr77335 2017-07-28 07:59
    关注

    FOS UserBundle's base User-model contains a serialize and unserialize that outputs the model's properties as array and then calls serialize on that and deserializes and sets itself from that array again.

    My assumption is that you either renamed some of those properties or you try to load a model which contains data that can not be handled by unserialize, e.g. because the data was truncated at some point or something weird like that. You might want to clear your old sessions, because as far as I know the serialize/unserialize is only used for storing the data in the session or you might want to start debugging by looking at the serialized data that it tries to unserialize.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法