Reputation: 2406
On Symfony 6, we can easly share an entty object through several fixtures class with the methods addReference
and getReference
. But theses methods handle only entities class managed by the entityManager.
If I create a simple value in a variable (an integer, a string) initialized during the first fixture, how can I pass the variable to the next fixtures called during the ./bin/console d:fixture:load
script ?
Thanks for any help !
Upvotes: 0
Views: 201
Reputation: 3312
addReference()
and getReference
are accessible by all your fixture classes, because they are implemented in a common base class Doctrine\Common\DataFixtures\AbstractFixture
.
If you want to share more than that, just make use of the same idea: Introduce your own parent class into the hierarchy and store everything you want to share on that parent:
abstract class MyFixturesParent extends AbstractFixture
{
protected int $mySharedInt = 1;
}
and implement your Fixtures as children of that parent
class MyFixtures extends MyFixturesParent
{
}
Upvotes: 1