我知道这有点晚了,但我只是想发布我的解决方案,也许会激发一些其他的想法。(以及对我工作方式的反馈)
我的初始来源: http: //marius-strajeru.blogspot.be/2013/02/create-system-config-section-with.html
所以要添加一个字段(例如:文本字段):
$field = $element->addField( 'myFieldID', 'text',
array(
'name' => 'groups[model_name][fields][var_name][value]', // this value will be saved to the database as module_name/model_name/var_name and you can get it by Mage::getStoreConfig(..)
'label' => 'Title', // This is the human readable label up front
// See how to get the saved value and define inherit in the link above, this is not in scope for this question. Like this you can't ever see the value that you saved.
'value' => 'My Title', // The initial value
'inherit' => true, // Checks the inherit cb after the field
'can_use_default_value' => true, // Can inherit from default level
'can_use_website_value' => true, // Can inherit from website level
))->setRenderer(Mage::getBlockSingleton('adminhtml/system_config_form_field')); // Use the same renderer as for the system fields (this adds the cb at the end)
这就是在字段中添加复选框所需要做的一切。如果您想添加那些灰色范围的文本(例如:[WEBSITE]):
$field['scope'] = true; // Display scope label
$field['scope_label'] = '[WEBSITE]';
可以这样做是因为定义了基本的 Varien 对象来实现 ArrayAccess
class Varien_Object implements ArrayAccess
现在渲染该字段:
echo $field->toHtml();