ZendSkeletonApplication に基づいたアプリケーションを持っているので、モデル間の関係を作成したいので:
user portal
id id
firstName name
lastName url
........
portal_Id
ユーザーフォームの選択オプションにデータベース値を入力したい
<?php
namespace Register\Form;
use Zend\Captcha\AdapterInterface as CaptchaAdapter;
use Zend\Form\Form;
use Zend\Form\Element;
class UserForm extends Form
{
protected $portalTable;
public function __construct($name = null)
{
parent::__construct('user');
$this->setAttribute('method', 'post');
$this->setAttribute('class', 'form-horizontal');
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'type' => 'Select',
'name' => 'portal_id',
'options' => array(
'label' => 'Portal',
'empty_option' => 'Seleccione un portal',
'value_options' => array(
'1' => 'portal 1',
'2' => 'portal 2',
'3' => 'portal 3',
//i want option from database with
),
)
));
$this->add(array(
'name' => 'firstName',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'First Name',
),
));
$this->add(array(
'name' => 'lastName',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Last Name',
),
));
$this->add(array(
'name' => 'login',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Login',
),
));
$this->add(array(
'name' => 'password',
'attributes' => array(
'type' => 'password',
),
'options' => array(
'label' => 'Password',
),
));
$this->add(array(
'name' => 'password_repeat',
'attributes' => array(
'type' => 'password',
),
'options' => array(
'label' => 'password (repeat)',
),
));
$this->add(array(
'name' => 'email',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Email',
),
));
$this->add(array(
'type' => 'Zend\Form\Element\Csrf',
'name' => 'csrf',
'options' => array(
'csrf_options' => array(
'timeout' => 600
)
)
));
$this->add( array(
'type' => 'Captcha',
'name' => 'captcha',
'options' => array(
'label' => 'Please verify you are human.',
'captcha' => array('class' => 'Dumb',
),
),
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}
この部分では、データベースから選択して入力したい
$this->add(array(
'type' => 'Select',
'name' => 'portal_id',
'options' => array(
'label' => 'Portal',
'empty_option' => 'Seleccione un portal',
'value_options' => array(
'1' => 'portal 1',
'2' => 'portal 2',
'3' => 'portal 3',
//i want option from database with
),
)
));
私の英語でごめんなさい