phpsymfonytwigfosuserbundlesymfony2-easyadmin

User extended from FOSUserBundle causes unserialize() Error at offset at Easyadmin list


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?


Solution

  • 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.