我在使用User(扩展FosUserBundle类)加入我的Article实体时遇到问题。当我查询数据库时它很好用,但是当我使用APC时:
$driver = \Doctrine\Common\Cache\ApcCache();
$driver->save($key, $queryResult)
,然后要求php$driver->fetch($key)
我只收到核心FosUserBundle列(id,电子邮件等)的数据,但我的额外列的数据是NULLS。
我有:
mappings:
FOSUserBundle: ~
在我的orm默认实体管理器配置中。知道会发生什么吗?
答案 0 :(得分:0)
问题在于
a)FOS \ UserBundle \ Model \ UserInterface extends \ Serializable
和
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;
}