malo91
Messages postés53Date d'inscriptionmardi 2 février 2021StatutMembreDernière intervention 3 août 2022
-
30 avril 2021 à 18:21
hello hello ! desolee car pas evident d'expliquer dans mon titre!
j'ai reussi à faire une categorie (menu deroulant affiché) sur mon trick ! je me suis faite un tableau de mes categories dans mon fichier fixtures/
class CategoriesFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
$faker = Faker\Factory::create('fr_FR');
$listCategory = [
1 => ['title' => 'grabs'],
2 => ['title' => 'straight airs'],
3 => ['title' => 'rotation'],
4 => ['title' => 'spins'],
5 => ['title' => 'flips and inverted rotations'],
6 => ['title' => 'inverted hand plants'],
7 => ['title' => 'stalls'],
8 => ['title' => 'slides'],
];
foreach($listCategory as $key => $value){
$listCategory = new Category();
$listCategory->setTitle($value['title']);
$listCategory->setDescription(($faker->paragraph(2)));
$manager->persist($listCategory);
//enregistrer la categorie dans une reference
$this->addReference('category_' . $key, $listCategory);
}
$manager->flush();
}
}
Dans mon fichier edit j'ai tous mes champs OK! ce qui me permet de modifier aussi ma listcategory si besoin!
En revanche sur mon fichier index donc la liste de mes tricks comprenant tous mes champs:
toujours la meme categorie sauf si je modifie en "edit" bien sur!
Alors suis allée voir ma function new TrickController :
mon formulaire TrickType et ma function Buildform a le champ category appelé :
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('description')
->add('createdAt')
->add('updateAt')
->add('category') ;
}
j'ai tenté de modifié sur le champ :( non
je me suis dit aussi qu'il fallait alors passer par ma fixture tricksFixtures , ce qui e semble logique et j'ai testé à ma ->setCategorie($category) j'avoue j'ai pas reussi!! encore trop novice !
bref peut être pourriez-vous m'aider un peu? merci et bon we