1

this is my first question, so sorry if I miss some information.

In my project I try to create a FormType with a ChoiceType. The ChoiceType should contain the weekdays (eg. monday, tuesday, etc).

Now I was wondering how I should deal with this exactly? First things which came in my mind are: - create a new weekday entity and store the weekdays in the database - put the weekdays in the choices as static array - somehow define a global array with the weekdays

I do not really like any solution though. So i was wondering if there is a general PHP way to get all weekday names for my ChoiceType. Also I'd like to reuse the same array multiple times (thats why I dont want to use a static array). The database solution could work, but that means I would have to define each weekday in every instance of my project - which also seems not ideal.

Thanks for any help

Haiberd
  • 124
  • 5
  • 1
    Hi, welcome to stackoverflow. Weekdays in database works for your problem. Just make sure that you use the `EnityType` instead of your `ChoiceType`. – Syllz Nov 28 '19 at 09:10
  • 1
    How exactly does that work? Thanks for the help – Haiberd Nov 28 '19 at 09:13
  • 1
    I assume you know how to create entities? If yours is called for eg. `Weekday` you can use following in your FormType `$builder->add('weekday', EntityType::class, ['class' => Weekday::class, 'choice_label' => 'name']);` that should work - also make sure that 'name' is your field where you save the weekday names – Syllz Nov 28 '19 at 09:16
  • I'll try that. Thank you – Haiberd Nov 28 '19 at 09:18

0 Answers0