Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

illegal Offset Type #411

Open
Sashkan opened this issue Oct 6, 2015 · 1 comment
Open

illegal Offset Type #411

Sashkan opened this issue Oct 6, 2015 · 1 comment

Comments

@Sashkan
Copy link

Sashkan commented Oct 6, 2015

I'm struggling with a genemu_jqueryselect2_choice

->add('departure', 'genemu_jqueryselect2_choice', array(
                'choices' => $airports,
                'label' => 'Departure',
            ))

in this case, $airports is an array of stdClass objects, which look like this :

array:1711 [▼
  0 => {#561 ▼
    +"lfi": "XXXXXXXX1"
    +"icao": "ENEG"
    +"iata": null
    +"faaCode": null
    +"name": " Eggemoen"
    +"city": " Eggemoen"
    +"countryCode": "FR"
    +"latitudeDecimal": "-60.2272220"
    +"longitudeDecimal": "10.3058330"
    +"utcStdConversion": null
  }
  1 => {#562 ▼
    +"lfi": "SP80307"
    +"icao": "LECO"
    +"iata": "LCG"
    +"faaCode": null
    +"name": "A CORUNA"
    +"city": "LA CORUNA"
    +"countryCode": "ES"
    +"latitudeDecimal": "43.3020611"
    +"longitudeDecimal": "-8.3772556"
    +"utcStdConversion": "+1"
  }
... 

This causes an error : Warning: Illegal offset type

How can I use this array as a select2 choice input ?

@WedgeSama
Copy link
Contributor

This is not a GenemuFormBundle specific case. If you try your code with the basic choice type, it normal throw the same warning.

In your case, I asume you do not want to use optgroup. So you have to give in place of the choices option, an associative array of key => string. And stdClass is not a string. If you want to give objects, define the method public function __toString() in your class (so create one for this and do not use stdClass). In this method, return the string you want to be display in the select input to represente your object.

At this time (maybe in a next release of Symfony), if you want to pass more then just a string, you cannot do that with default choice form type (same for genemu_jqueryselect2_choice).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants