我在将 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/