Joomla源代码解析(二十二) 模块是如何被调用执行并渲染(下)

上一文章中提到了getBuffer函数,在函数中实际上调用了render ,这个对象是JDocumentRendererModule 类的实例,我们看看JDocumentRendererModule 的render函数。

if (!is_object($module))
{
$module =& JModuleHelper::getModule($module);

if (!is_object($module))
{
if (is_null($content)) {
return '';
} else {
/**
* If module isn't found in the database but data has been pushed in the buffer
* we want to render it
*/
$tmp = $module;
$module = new stdClass();
$module->params = null;
$module->module = $tmp;
$module->id = 0;
$module->user = 0;
}
}
}

// get the user and configuration object
$user =& JFactory::getUser();
$conf =& JFactory::getConfig();

// set the module content
if (!is_null($content)) {
$module->content = $content;
}

//get module parameters
$mod_params = new JParameter( $module->params );

$contents = '';
if ($mod_params->get('cache', 0) && $conf->getValue( 'config.caching' ))
{
$cache =& JFactory::getCache( $module->module );

$cache->setLifeTime( $mod_params->get( 'cache_time', $conf->getValue( 'config.cachetime' ) * 60 ) );
$cache->setCacheValidation(true);

$contents = $cache->get( array('JModuleHelper', 'renderModule'), array( $module, $params ), $module->id. $user->get('aid', 0) );
} else {
$contents = JModuleHelper::renderModule($module, $params);
}

这段代码完成了找到对应的module ,和helper文件,兑取参数,并最后由'JModuleHelper'执行,并渲染。

至此,我们也完全了解了模板是如何被调用,模块是如何并调用并渲染的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值