使用 FOS doctrineFIxture 中的服务容器
use the service container in FOS doctrineFIxture
我正在使用 DoctrineFixtureBundle 来管理我的网络应用程序中的设备,我想使用默认图像来初始化媒体。
为此,我需要访问服务容器以获取 RootDir
参数。这是我的装置:
use Doctrine\Bundle\FixturesBundle\Fixture;
class AppFixtures extends Fixture
{
private $passwordEncoder;
public function __construct(UserPasswordEncoderInterface $passwordEncoder)
{
$this->passwordEncoder = $passwordEncoder;
}
public function load(ObjectManager $manager)
{
$root = new User();
//init user parameters
$image = new Image();
$image->setImageFile(fopen($this->container->getRootDir().'public/image/default/no-profile-pic/jpg', 'r'));
$root->setProfilePic($image);
$manager->persist($root);
}
}
我按照这个 documentation 但是它 return 我出现了以下错误 :
Notice: Undefined property: App\DataFixtures\AppFixtures::$container
是我傻还是 AppFixture class 不知道容器?
访问完整容器不再是解决方案。您需要通过更改密码编码器
的 class 定义来使用 DI
我正在使用 DoctrineFixtureBundle 来管理我的网络应用程序中的设备,我想使用默认图像来初始化媒体。
为此,我需要访问服务容器以获取 RootDir
参数。这是我的装置:
use Doctrine\Bundle\FixturesBundle\Fixture;
class AppFixtures extends Fixture
{
private $passwordEncoder;
public function __construct(UserPasswordEncoderInterface $passwordEncoder)
{
$this->passwordEncoder = $passwordEncoder;
}
public function load(ObjectManager $manager)
{
$root = new User();
//init user parameters
$image = new Image();
$image->setImageFile(fopen($this->container->getRootDir().'public/image/default/no-profile-pic/jpg', 'r'));
$root->setProfilePic($image);
$manager->persist($root);
}
}
我按照这个 documentation 但是它 return 我出现了以下错误 :
Notice: Undefined property: App\DataFixtures\AppFixtures::$container
是我傻还是 AppFixture class 不知道容器?
访问完整容器不再是解决方案。您需要通过更改密码编码器
的 class 定义来使用 DI