簡體   English   中英

在magento中使用system.xml禁用/啟用magento中的模塊

[英]Disable/Enable module in magento using system.xml in magento

我已經知道如何通過轉到System> Configuration> Advanced並在etc / modules中設置<active>false</active>來禁用系統配置中的模塊輸出。 我想知道的是如何使用我使用system.xml創建的自定義選項卡禁用模塊。

將此代碼添加到您的system.xml

<fields>
    <enable translate="label">
        <label>Enable</label>
        <frontend_type>select</frontend_type>
        <source_model>adminhtml/system_config_source_yesno</source_model>
        <sort_order>0</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
        <comment>enable/disable the module</comment>
    </enable>
</fields>

並在代碼中進行檢查:在模塊中執行第一個Action之前(可能在cron.php or observer.php or indexcontroller

$isenabled = Mage::getStoreConfig('section_name/group_name/enable');
if (!$isenabled) {
    return;
}

您可以在system.xml中添加新的Enable / Disable字段,並且在模塊執行任何代碼之前,請檢查該字段值(如果已啟用),然后執行否則否則不執行,這樣是可能的。

您必須在XML文件中使用ifconfig

例如,您在system.xml中創建一個字段

 <enable translate="label">
<label>enable</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>

並在您的xml文件中

<block class="your Blockname" name="name of field" ifconfig="sectionname/groupname/enable">

如果模塊已啟用,則使用if config,則它將顯示,否則將不顯示..!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM