我正在尝试将一些用户加载到我的数据库中,以便使用 DoctrineFixturesBundle 进行测试。我在 StackOverflow 上进行了很多搜索,并发现了很多关于其他问题的信息。不过,似乎没有人有我的答案。我正在使用 FOS 用户管理器加载我的用户。下面是我的夹具类。
namespace Kandidly\UserBundle\DataFixtures;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
private $container;
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$userManager = $this->container->get('fos_user.user_manager');
$user1 = $userManager->createUser();
$user1->setFirstName('Admin');
$user1->setLastName('User');
$user1->setCity('Somewhere');
$user1->setState('TN');
$user1->setUsername('admin');
$user1->setEmail('admin@example.com');
$user1->setPlainPassword('admin');
$user1->setEnabled(true);
$user1->setRoles(
array(
'ROLE_ADMIN'
)
);
$user2 = $userManager->createUser();
$user2->setFirstName('Normal');
$user2->setLastName('User');
$user2->setCity('Another');
$user2->setState('CA');
$user2->setUsername('user');
$user2->setEmail('use@example.com');
$user2->setPlainPassword('user');
$user2->setEnabled(true);
$user2->setRoles(
array(
'ROLE_USER'
)
);
$userManager->updateUser($user1);
$userManager->updateUser($user2);
$this->addReference('admin-user', $user1);
}
/**
* Get the order of this fixture
*
* @return integer
*/
function getOrder()
{
return 1;
}
/**
* Sets the Container.
*
* @param ContainerInterface|null $container A ContainerInterface instance or null
*
* @api
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
}
但是,当我运行固定装置时,我收到一条错误消息,指出未设置盐。任何人都可以帮忙吗?