Symfony APC不在fosuserbundle扩展类中保存属性

Symfony APC不在fosuserbundle扩展类中保存属性,symfony,orm,doctrine,fosuserbundle,apc,Symfony,Orm,Doctrine,Fosuserbundle,Apc,我在将我的文章实体与User(扩展了FosUserBundle类)连接时遇到问题。当我查询数据库时效果很好,但当我使用APC时: $driver=\doctor\Common\Cache\ApcCache(); $driver->save($key,$queryResult),然后请求php$driver->fetch($key) 我只接收核心FosUserBundle列(id、email等)的数据,但额外列的数据为空 我有: 映射: FOSUserBundle:~ 在我的orm默认实体管理器

我在将我的文章实体与User(扩展了FosUserBundle类)连接时遇到问题。当我查询数据库时效果很好,但当我使用APC时:

$driver=\doctor\Common\Cache\ApcCache();
$driver->save($key,$queryResult)
,然后请求
php$driver->fetch($key)
我只接收核心FosUserBundle列(id、email等)的数据,但额外列的数据为空

我有:

映射:
FOSUserBundle:~


在我的orm默认实体管理器配置中。知道会发生什么吗

问题在于

a) FOS\UserBundle\Model\UserInterface extends\Serializable

b) FOS\UserBundle\Model\User实现了它

你需要做的是重写

public function serialize()

使用将附加字段考虑在内的implementation

/**
 * Serializes the user.
 *
 * The serialized data have to contain the fields used by the equals method and the username.
 *
 * @return string
 */
public function serialize()
{
    return serialize(array(
        $this->password,
        $this->salt,
        $this->usernameCanonical,
        $this->username,
        $this->expired,
        $this->locked,
        $this->credentialsExpired,
        $this->enabled,
        $this->id,
        $this->someCustomField,
    ));
}


/**
 * Unserializes the user.
 *
 * @param string $serialized
 */
public function unserialize($serialized)
{
    $data = unserialize($serialized);
    // add a few extra elements in the array to ensure that we have enough keys when unserializing
    // older data which does not include all properties.
    $data = array_merge($data, array_fill(0, 2, null));

    list(
        $this->password,
        $this->salt,
        $this->usernameCanonical,
        $this->username,
        $this->expired,
        $this->locked,
        $this->credentialsExpired,
        $this->enabled,
        $this->id,
        $this->someCustomField
    ) = $data;
}

您是否可以尝试将
映射:FOSUserBundle:~
替换为:
自动映射:true
?@ilyarkovets即使多个实体管理器都未启用自动映射。我有两个,并删除了一个,但这没有帮助
/**
 * Serializes the user.
 *
 * The serialized data have to contain the fields used by the equals method and the username.
 *
 * @return string
 */
public function serialize()
{
    return serialize(array(
        $this->password,
        $this->salt,
        $this->usernameCanonical,
        $this->username,
        $this->expired,
        $this->locked,
        $this->credentialsExpired,
        $this->enabled,
        $this->id,
        $this->someCustomField,
    ));
}


/**
 * Unserializes the user.
 *
 * @param string $serialized
 */
public function unserialize($serialized)
{
    $data = unserialize($serialized);
    // add a few extra elements in the array to ensure that we have enough keys when unserializing
    // older data which does not include all properties.
    $data = array_merge($data, array_fill(0, 2, null));

    list(
        $this->password,
        $this->salt,
        $this->usernameCanonical,
        $this->username,
        $this->expired,
        $this->locked,
        $this->credentialsExpired,
        $this->enabled,
        $this->id,
        $this->someCustomField
    ) = $data;
}