正如Elin所说,JModuleHelper只能在后端调用它时才能在后端加载模块。遵循Elin的链接,您可以找到源代码JModuleHelper以及从数据库中读取模块信息的实际功能load()
。 (警告:该行可能会在未来发生改变),这里是我的 “黑客” 我的应用程序(在测试的Joomla 3.1.5!):
function getModule($moduleName, $instanceTitle = null){
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params')
->from('#__modules AS m')
->where(Array(
'm.published = 1'
, 'm.module = ' . $db->quote($moduleName)
));
if ($instanceTitle){
$query->where('m.title = ' . $db->quote($instanceTitle));
}
$db->setQuery($query);
try
{
$modules = $db->loadObject(); // You might want to use loadObjectList() instead
}
catch (RuntimeException $e)
{
JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $e->getMessage()), JLog::WARNING, 'jerror');
$clean = array();
return $clean;
}
return $modules;
}
使用案例:
$module = getModule('mod_your_module', 'The name of the module instance');
$params = new JRegistry;
$params->loadString($module->params);
require_once JPATH_SITE . '/modules/mod_your_module/helper.php'; // I have a helper class to format the params before render. So I reuse this helper here.
$params = ModYourModuleHelper::getParams($params);