2012-11-06 40 views
4

我有一個文件,其中包含美國各州的列表。
阿拉巴馬
阿拉斯加
等。如何在Symfony 2.1中使用ChoiceList?

在symfony的2.0我用ChoiceListInterface.php在我的形式使用它。我只是寫了這個:

<?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; 

    } 
} 

但現在還有其他7個功能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); 

我已閱讀文檔http://api.symfony.com/2.1/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.html但對我來說,我覺得它不清楚,我真不」瞭解如何實施它們。

有人可以幫忙嗎?非常感謝

回答