symfony - APC 不保存 fosuserbundle 扩展类中的属性

标签 symfony orm doctrine fosuserbundle apc

我在将 Article 实体与 User(扩展 FosUserBundle 类)连接时遇到问题。当我查询数据库时它工作得很好,但是当我使用 APC 时: $driver =\Doctrine\Common\Cache\ApcCache(); $driver->save($key, $queryResult),然后请求php$driver->fetch($key) 我仅收到核心 FosUserBundle 列(id、电子邮件等)的数据,但额外列的数据为 NULL。

我有:

映射: FOSUserBundle:~

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

最佳答案

问题在于

a) FOS\UserBundle\Model\UserInterface 扩展\Serialized

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

你需要做的是覆盖

public function serialize()

public function unserialize($serialized)

具有考虑您的附加字段的实现。

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

关于symfony - APC 不保存 fosuserbundle 扩展类中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35086875/

相关文章:

php - 如何在 Doctrine 中选择最近 2 小时的行

symfony - symfony2 是否可以使用双重身份验证?

php - Doctrine 通过魔法查找空值

java - 更新 : could not execute statement, 时出现 Hibernate 错误 在 'index=1' 附近使用正确的语法

Symfony 2 - sylius - Doctrine 不可用

regex - 使用正则表达式来验证字符串

sqlite - 在使用 SQLite 数据库时并行化功能测试

php - 通过更改查询字符串参数在 Symfony2 中进行简单重定向,与路由无关

java - Hibernate - 对条件结果执行 HQL 查询

c++ - 通过 Qt 中的 QDataWidgetMapper 将单选按钮连接到 QSqlTableModel