1

Symfony2: Error SecurityDataCollector

Se in seguito all’aggiornamento del PHP, la vostra webapp Symfony2 presenta il seguente errore:

 

FatalErrorException: Error: Call to a member function getRole() on a non-object in
C:\xampp\htdocs\AppApartamentos\vendor\symfony\sym fony\src\Symfony\Bundle\SecurityBundle\DataCollect or\SecurityDataCollector.php line 60

dovete aggiungere un metodo “serialize” alla vostra classe User.

Aprite l’Entità User.php:

modificate la dichiarazione in:

class User implements UserInterface, \Serializable

ed aggiungete i seguenti metodi:

public function serialize()
{
return json_encode(
array($this->username, $this->password, $this->salt,
$this->user_roles, $this->id));
}

/**
* Unserializes the given string in the current User object
* @param serialized
*/
public function unserialize($serialized)
{
list($this->username, $this->password, $this->salt,
$this->user_roles, $this->id) = json_decode(
$serialized);
}

 

 

La vostra istallaizione è salva!