【发布时间】:2015-05-25 05:26:00
【问题描述】:
我正在使用 PHP Zendframework 来构建表单。我有我需要用来填充我的 ServiceEditForm.php 的服务对象。但在这种服务形式中,我有“计费”、“订阅”对象和“命令”对象数组。下面是我对服务类的实现。
class Service{
public $service_id;
public $ServiceName;
public $TelecomOperator;
public $SubMethod;
public $Provider;
public $active;
public $billingType;
public $subscriptionPlan;
public $commands;
function exchangeArray(array $data);}
我想将服务类的对象绑定到我的编辑表单,该表单使用订阅、计费和命令相关数据作为字段集。我能够使用绑定而不是其他对象来填充表单中的服务值。这是我的表单实现
class ServiceEditForm extends Form{
public function __construct($name = null)
{
parent::__construct('Edit Service');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype','multipart/form-data');
//here i have other fields that belongs to service object
$this->add( array(
'name' => 'billingType',
'type' => 'Services\Form\BillingTypeFieldset',
'options' => array(
'label' => 'Billing Type',
),
));
$this->add( array(
'name' => 'subscriptionPlan',
'type' => 'Services\Form\SubscriptionPlanFieldset',
'options' => array(
'label' => 'Subscription Plan',
),
));
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'commands',
'options' => array(
'label' => 'commands',
'count' => 2,
'should_create_template' => true,
'allow_add' => true,
'target_element' => array(
'type' => 'Services\Form\CommandFieldset',
),
),
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Save'
),
));
}
}
正如我所说,我无法使用此实现在表单内填充带有绑定的字段集。任何建议将不胜感激。
【问题讨论】:
-
我能够研究一下并能够解决(但不完全理解背后的概念)。我用 ArraySerializable 替换了 hydrator ClassMethods 并为我做了一个转变。
标签: php data-binding zend-framework2