我試圖加載一些用戶到我的數據庫進行測試使用DoctrineFixturesBundle。我在StackOverflow上做了很多搜索,並且發現了很多其他的問題。但似乎沒有我的答案。我正在使用FOS用戶管理器加載用戶。以下是我的夾具課。FOSUserBundle Not Setting Salt In DoctrineFixtures
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('[email protected]');
$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('[email protected]');
$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;
}
}
但是,當我運行燈具,我得到一個錯誤,說鹽沒有被設置。誰能幫忙?
salt在抽象'FOS \ UserBundle \ Model \ User'的構造函數中設置。你在擴展那個類,但是不在你的具體類中調用它的構造函數嗎? – Ryan