我在system.xml中为输入字段指定了frontend_model。我这样做是因为我想让字段只读。可能有更直接的方法来实现这一目标,但这正是我目前所处的位置。事情是我无法让领域显示它应该的数据。Magento配置 - 使用frontend_model时填充字段
我有一个按钮,当按下时,填充只读字段。这工作正常。但是当我点击“保存配置”时,数据从现场消失。它消失的原因是因为我无法找出我应该设置该字段的价值。下面尝试使用Varien_Data_Form_Element_Abstract的getEscapedValue()方法,但它不返回任何内容。和往常一样,Magento没有任何文件可言。
class Mypackage_MyModule_Block_Adminhtml_System_Config_DisabledText extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _prepareLayout()
{
parent::_prepareLayout();
if (!$this->getTemplate()) {
$this->setTemplate('mypackage/system/config/disabled_text.phtml');
}
return $this;
}
public function render(Varien_Data_Form_Element_Abstract $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$originalData = $element->getOriginalData();
$this->addData(array(
'my_value' => $element->getEscapedValue(),
'html_id' => $element->getHtmlId(),
));
return $this->_toHtml();
}
}
disabled_text.phtml包含以下内容:
<input id="<?php echo $this->getHtmlId() ?>" value="<?php echo $this->getMyValue(); ?>" class=" input-text" type="text" disabled/>
感谢。
似乎忘记为输入元素指定名称,因此当您按save config按钮时,您的字段不会发送到保存配置的控制器。 – 2011-04-12 12:17:13
嗨 - 我尝试添加名称属性到html 元素,但这没有什么区别。即使这会导致控制器保存配置,当getMyValue()返回任何内容时(因为$ element-> getEscapedValue()),当然我会将html值设置为“<?php echo $ this-> getMyValue()?>” ()什么都没有返回)会重置值为空? – user649650 2011-04-12 13:51:35