我在模板文件中有一小段代码,如果安装了某个模块,我只想运行.我找到了以下代码,您可以使用它来查找模块是否处于活动状态,但我想知道是否安装了模块.
$modules = Mage::getConfig()->getNode('modules')->children();
$modulesArray = (array)$modules;
if($modulesArray['Mage_Paypal']->is('active')) {
echo "Paypal module is active.";
} else {
echo "Paypal module is not active.";
}
Run Code Online (Sandbox Code Playgroud)
我想我可能会得到所有已安装模块的名称列表,然后使用
if (stristr($modulelist, 'Name_Extension'))
Run Code Online (Sandbox Code Playgroud)
仅在安装引用的扩展名时显示我的代码.
任何想法如何做到这一点?还是更好的解决方案?
bao*_*tch 88
有一个核心帮手:
Mage::helper('core')->isModuleEnabled('MyCompany_MyModule');
Run Code Online (Sandbox Code Playgroud)
它在Mage_Core_Helper_Abstract.
还有一种isModuleOutputEnabled()方法可以检查系统 - >配置 - >高级 - >禁用模块输出中是否禁用模块输出.
Jos*_*tey 10
试试这个:
$modules = Mage::getConfig()->getNode('modules')->children();
$modulesArray = (array)$modules;
if(isset($modulesArray['Mage_Paypal'])) {
echo "Paypal module exists.";
} else {
echo "Paypal module doesn't exist.";
}
Run Code Online (Sandbox Code Playgroud)
查找模块是否已安装但已禁用的另一种方法是:
if (Mage::getStoreConfigFlag('advanced/modules_disable_output/Mage_Paypal')) {
echo "Paypal module is installed";
}
Run Code Online (Sandbox Code Playgroud)
编辑
刚刚意识到这个版本 - 使用鲜为人知的ifconfig- 只有在禁用另一个模块时才能显示一个块.例如.
<layout>
<default>
<reference name="content">
<block ifconfig="advanced/modules_disable_output/Mage_Paypal" type="core/template" template="sorry/this/is/unavailable.phtml" />
</reference>
</default>
</layout>
Run Code Online (Sandbox Code Playgroud)