Jak korzystać z ChoiceList w Symfony 2.1?
Mam plik zawierający listę stanów USA.
Alabama
Alaska
etc ..
W symfony 2.0 użyłem ChoiceListInterface.php do użycia go w mojej formie. Po prostu to napisałem:
<?php
namespace MyBundle\Form;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
class StateChoiceList implements ChoiceListInterface
{
public function getChoices()
{
$lines = file('listes/us_states.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// fill the array
$arr = array();
foreach ($lines as $line) {
$arr[$line] = $line;
}
return $arr;
}
}
Ale teraz jest 7 innych funkcji do wdrożenia w ChoiceListInterface:
public function getValues();
public function getPreferredViews();
public function getRemainingViews();
public function getValuesForChoices(array $choices);
public function getIndicesForChoices(array $choices);
public function getIndicesForValues(array $values);
Przeczytałem dokumentacjęhttp://api.symfony.com/2.1/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.html ale w moim przypadku jest to niejasne i naprawdę nie rozumiem, jak je wdrożyć.
Ktoś mógłby pomóc? Wielkie dzięki