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'执行,并渲染。

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

posted on 2009-12-20 14:02  14的路  阅读(463)  评论(0编辑  收藏  举报

导航

友情链接:源码下载