Skip to content

Instantly share code, notes, and snippets.

@KhanMaytok
Last active December 14, 2015 21:59
Show Gist options
  • Save KhanMaytok/8b39f9c8c65cd6e6c85a to your computer and use it in GitHub Desktop.
Save KhanMaytok/8b39f9c8c65cd6e6c85a to your computer and use it in GitHub Desktop.
Create DoctrineFixtures with FOSUserBundle
<?php
// Change the namespace!
namespace Acme\DemoBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LoadUserData implements FixtureInterface, ContainerAwareInterface
{
//.. $container declaration & setter
public function load(ObjectManager $manager)
{
// Get our userManager, you must implement `ContainerAwareInterface`
$userManager = $this->container->get('fos_user.user_manager');
// Create our user and set details
$user = $userManager->createUser();
$user->setUsername('username');
$user->setEmail('[email protected]');
$user->setPlainPassword('password');
//$user->setPassword('3NCRYPT3D-V3R51ON');
$user->setEnabled(true);
$user->setRoles(array('ROLE_ADMIN'));
// Update the user
$userManager->updateUser($user, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment