I'm making a module in which the user can add review scores from another site.
It currently looks like this.
And I want to add a function like this:
Does anyone know how I can achieve this?
I'm making a module in which the user can add review scores from another site.
It currently looks like this.
And I want to add a function like this:
Does anyone know how I can achieve this?
What you are looking for is what Magento defines under adminhtml/system_config_backend_serialized_array
.
This will allow you to create an input table in the admin with a user defined number of rows.
This is used for example in Configuration > GENERAL > Design
and looks like this:
Add this to your Vendorname/Modulename/etc/system.xml (make sure you update the module name and node labels accordingly):
<config>
<tabs>
<vendor translate="label" module="vendorname_modulename">
<label>Tab Name</label>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</vendor>
</tabs>
<sections>
<modulename_settings translate="label" module="vendorname_modulename">
<groups>
<label>Group Label</label>
<tab>vendor</tab>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<some_options translate="label">
<label>Section Label</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<params module="vendorname_modulename">
<label>Table Label</label>
<frontend_model>vendorname_modulename/adminhtml_system_config_source_table</frontend_model>
<backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
<sort_order>200</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</params>
</fields>
</some_options>
<!-- [...] -->
</groups>
</modulename_settings>
<!-- [...] -->
</sections>
</config>
Then, as specified in the frontend_model (=Block!) node, create Vendorname/Modulename/Block/Adminhtml/System/Config/Source/Table.php and put this inside:
<?php
class Vendorname_Modulename_Block_Adminhtml_System_Config_Source_Table extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract {
public function _prepareToRender() {
$this->addColumn('column_a', array(
'label' => 'Column A',
'style' => 'width:200px',
));
$this->addColumn('column_b', array(
'label' => 'Column B',
'style' => 'width:200px',
));
$this->_addAfter = false;
$this->_addButtonLabel = 'Add line';
}
}
You then can get the content of this table like always using Mage::getStoreConfig()
- but in order to utilize the values you will have to unserialize()
it.