ZF2 のフォーム要素の選択に問題があります。私はクエリ教義 2 を作成し、良い結果オブジェクト リストを持っています。
$langs = $this->getEntityManager()->getRepository('Application\Entity\Langs')->findAll();
そして、単純なフォームを作成します:
class Coupon extends Form
{
protected $objectManager;
public function __construct($name = null)
{
parent::__construct('coupon');
$this->setAttribute('method', 'post');
$this
->setAttribute('method', 'post')
->setHydrator(new ClassMethodsHydrator(false))
;
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden',
),
));
}
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'language',
'attributes' => array(
'class' => 'form-control',
),
'options' => array(
'label' => 'default.form.message',
'empty_option' => '--- choose formElementName ---',
'value_options' => array(
'0' => 'French',
'1' => 'English',
'2' => 'Japanese',
'3' => 'Chinese',
),
)
));
}
結果 ($langs) を value_options - zend 要素選択の配列に変換するにはどうすればよいですか? これには何を使用すればよいですか?