是否可以在由集合創建的字段集中設置id?我有幾個實體(用戶,地址,附件等),在我的用戶實體中,我有幾個使用集合創建的字段集。所以用戶可以有多個地址或附件。我的收藏品是這樣構建的:如何在集合字段集(doctrine 2,zend framework 2)上設置屬性(id)
$addressFieldset = new AddressFieldset($serviceManager);
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'addresses',
'options' => array(
'label' => 'Choose address for user',
'count' => 1,
'should_create_template' => true,
//'template_placeholder' => '__placeholder__',
'allow_add' => true,
'target_element' => $addressFieldset
),
));
$this->add(array(
'name' => 'addAddress',
'type' => 'button',
'options' => array('label' => 'Add Address',
),
));
$this->get('addAddress')->setAttribute('onclick', 'return add_address()');
我的問題是我在我的userfieldset中有多個集合。所以,當我要動態地添加一些地址(例如,我使用:http://zf2.readthedocs.org/en/latest/modules/zend.form.collections.html)中,例如有以下的javascript:
function add_address() {
var currentCount = $('form > fieldset > fieldset').length;
var template = $('form > fieldset > span').data('template');
template = template.replace(/__index__/g, currentCount);
$('form > fieldset').append(template);
return false;
}
但是,我的問題是,如果我使用的例子,它增加了addressfieldsets也附件下。我想是這樣的:
function add_address() {
var currentCount = $('form > #addressFieldset > fieldset').length;
var template = $('form > #addressFieldset > span').data('template');
template = template.replace(/__index__/g, currentCount);
$('form > #addressFieldset').append(template);
return false;
}
有了這個,我只能訪問addressFieldset,但我怎麼能在AddressFieldset設置一個ID? 我的樹應該是這樣的:
<form>
<fieldset id="addressFieldset">
<legend>Choose addresses</legend>
<fieldset>
//Data
</fieldset>
</fieldset>
<fieldset id="attachmentFieldset">
<legend>Choose attachments</legend>
<fieldset>
//Data
</fieldset>
</fieldset>
</form>
我不知道如何設置的ID在字段集。請幫助
我在我的視圖中創建了帶id的字段集。在zend中,現在需要在表單集合中設置一個id,因爲該viewhelper只在字段集本身設置了圖例。所以在字段集上沒有任何屬性。當然,它有助於謝謝你 – Haidy 2013-05-08 14:34:50