私は備品を実行しようとしているが、私は自分のパスワードをエンコードするためにUserPasswordEncoderInterface
を注入しようとしているとき、私はこのメッセージを持っているdoctrine/doctrine-fixtures-bundle": "2.4.1
symfonyの3.4及び備品バンドル
でsymfonyの3.4.1を使用しています。 https://symfony.com/doc/master/bundles/DoctrineFixturesBundle/index.html#accessing-services-from-the-fixtures
Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Too few arguments to function AppBundle\DataFixtures\DataFixtures::__construct(), 0 passed in /srv/api-platform/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php on line 210 and exactly 1 expected in /srv/api-platform/src/AppBundle/DataFixtures/ORM/DataFixtures.php:20 Stack trace:
0 /srv/api-platform/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php(210):
AppBundle\DataFixtures\DataFixtures->__construct()
1 /srv/api-platform/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php(390):
Doctrine\Common\DataFixtures\Loader->createFixture('AppBundle\DataF...')
2 /srv/api-platform/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php(82):
Doctrine\Common\DataFixtures\Loader->loadFromIterator(Object(RecursiveIteratorIterator))
3 /srv/api-platform/vendor/doctrine/doctrine-fixtures-bundle/Command/LoadDataFixturesDoctrineCommand.php(102):
Doctrine\Commo in /srv/api-platform/src/AppBundle/DataFixtures/ORM/DataFixtures.php on line 20
マイ対戦:
<?php
namespace AppBundle\DataFixtures;
use AppBundle\Entity\TechnicalCenter;
use AppBundle\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class DataFixtures extends Fixture
{
/** @var UserPasswordEncoderInterface $encoder */
private $encoder;
/**
* DataFixtures constructor.
* @param UserPasswordEncoderInterface $encoder
*/
public function __construct(UserPasswordEncoderInterface $encoder)
{
$this->encoder = $encoder;
}
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$technicalCenter = new TechnicalCenter();
$technicalCenter->setName('Austerlitz');
$manager->persist($technicalCenter);
$admin = new User();
$admin->setUsername('admin');
$admin->setPassword($this->encoder->encodePassword($admin, 'admin'));
$admin->setRoles(array('ROLE_ADMIN'));
$admin->setTechnicalCenter($technicalCenter);
$manager->persist($admin);
$manager->flush();
}
}
マイsecurity.yml
器具において
security:
encoders:
AppBundle\Entity\User: bcrypt
標準のサービス設定を使用していますか?つまり、services.ymlファイルはSymfony 3.4の標準の場所にありますか? – ASOlivieri
もしそうでなければ(あるいはそうであっても)あなたのサービスを登録してエンコーダを注入しようとしましたか? – ASOlivieri