Skip to content

Instantly share code, notes, and snippets.

@webmozart
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webmozart/5db8b44c88dc0ae11dbe to your computer and use it in GitHub Desktop.
Save webmozart/5db8b44c88dc0ae11dbe to your computer and use it in GitHub Desktop.
$form->add('field', 'choice', array(
'choices' => array(
'Yes' => true,
'No' => false,
'Maybe' => null,
),
));
// $list->getValues(): ['0', '1', '2']
// $list->getChoices(): [0 => true, 1 => false 2 => null]
// $list->getThings(): [0 => 'Yes', 1 => 'No', 2 => 'Maybe']
$form->add('field', 'choice', array(
'choices' => array(
'Yes' => true,
'No' => false,
'Maybe' => null,
),
'choice_value' => function ($choice, $label) {
return strtolower($label);
},
));
// $list->getValues(): ['yes', 'no', 'maybe']
// $list->getChoices(): ['yes' => true, 'no' => false, 'maybe' => null]
// $list->getThings(): ['yes' => 'Yes', 'no' => 'No', 'maybe' => 'Maybe']
$form->add('field', 'choice', array(
'choices' => array($yesObj, $noObj, $maybeObj),
'choice_value' => function ($obj) {
return strtolower($obj->getText());
},
'choice_label' => function ($obj) {
return $obj->getText();
}
));
// $list->getValues(): ['yes', 'no', 'maybe']
// $list->getChoices(): ['yes' => $yesObj, 'no' => $noObj, 'maybe' => $maybeObj]
// $list->getThings(): ['yes' => 0, 'no' => 1, 'maybe' => 2]
$form->add('field', 'choice', array(
'choices' => array(
'Decided' => array($yesObj, $noObj)
'Undecided' => array($maybeObj),
),
'choice_value' => function ($obj) {
return strtolower($obj->getText());
},
'choice_label' => function ($obj) {
return $obj->getText();
}
));
// $list->getValues(): ['yes', 'no', 'maybe']
// $list->getChoices(): ['yes' => $yesObj, 'no' => $noObj, 'maybe' => $maybeObj]
// $list->getThings(): ['yes' => 0, 'no' => 1, 'maybe' => 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment