What properties (and why) should be included in the serialize()
and deserialize()
methods in Symfony 2?
Now I have an id
field and it just works, but I would like to know why and what is the purpose of serialize()
in the User
class. to avoid this message:
You cannot upgrade a user from EntityUserProvider that does not contain an identifier. A custom object must be serialized using its own identifier displayed by Doctrine.
Class User implements AdvancedUserInterface, \Serializable { public function serialize() { return serialize($this->id); } public function unserialize($data) { $this->id = unserialize($data); } }
Without implementing \Serializable
and with all protected
properties, I get:
Symfony \ Component \ Security \ Basic \ Authentication \ Token \ UsernamePasswordToken :: serialization () should return a string or NULL.
gremo source share