Skip to content

Updated "Load security users from database" #1874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions cookbook/security/entity_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ The code below shows the implementation of the
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class));
}

return $this->loadUserByUsername($user->getUsername());
return $this->findOneById($user->getId());
}

public function supportsClass($class)
Expand Down Expand Up @@ -429,7 +429,7 @@ returns the list of related groups::
use Doctrine\Common\Collections\ArrayCollection;
// ...

class User implements AdvancedUserInterface
class User implements AdvancedUserInterface, \Serializable
{
/**
* @ORM\ManyToMany(targetEntity="Group", inversedBy="users")
Expand All @@ -448,6 +448,26 @@ returns the list of related groups::
{
return $this->groups->toArray();
}

/**
* @see \Serializable::serialize()
*/
public function serialize()
{
return serialize(array(
$this->id,
));
}

/**
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list (
$this->id,
) = unserialize($serialized);
}
}

The ``AcmeUserBundle:Group`` entity class defines three table fields (``id``,
Expand Down