Magento addField不使用'value'

时间:2012-06-11 16:07:49

标签: php magento mage adminhtml

设置自定义表单。 Magento不使用addField的'value'属性。建议?

代码:

$form = new Varien_Data_Form(array(
    'id' => 'edit_form',
    'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
    'method' => 'post',
    'enctype' => 'multipart/form-data',
));

$form->setUseContainer(true);
$this->setForm($form);

$fieldset = $form->addFieldset('example_form', array(
     'legend' =>Mage::helper('categoryrules')->__('Example Information')
));

...

$entityType = Mage::getModel('eav/config')->getEntityType('test_category_rule');
$entityTypeId = $entityType->getEntityTypeId();

...

$fieldset->addField('entity_type_id', 'hidden', array(
      'name'               => 'entity_type_id',
      'value'              => $entityTypeId
));

输出:

<input id="entity_type_id" name="entity_type_id" value="" type="hidden">

修改

print_r的结果($ entityType-&gt; debug());

Array ( 
    [entity_type_id] => 11 
    [entity_type_code] => rogue_category_rule 
    [entity_model] => categoryrules/rules 
    [attribute_model] => 
    [entity_table] => categoryrules/rules 
    [value_table_prefix] => 
    [entity_id_field] => 
    [is_data_sharing] => 1 
    [data_sharing_key] => default 
    [default_attribute_set_id] => 0 
    [increment_model] => 
    [increment_per_store] => 0 
    [increment_pad_length] => 8 
    [increment_pad_char] => 0 
    [additional_attribute_table] => 
    [entity_attribute_collection] => 
)

1 个答案:

答案 0 :(得分:3)

尝试在此处写下任何常量:

$fieldset->addField('entity_type_id', 'hidden', array(
      'name'               => 'entity_type_id',
      'value'              => 11
));

或者:

$fieldset->addField('entity_type_id', 'hidden', array(
      'name'               => 'entity_type_id'
));
$form->setValues($entityType->getData());