Last active
December 14, 2015 21:59
-
-
Save KhanMaytok/8b39f9c8c65cd6e6c85a to your computer and use it in GitHub Desktop.
Create DoctrineFixtures with FOSUserBundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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