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'執行,並渲染。

至此,我們也完全瞭解了模板是如何被調用,模塊是如何並調用並渲染的。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章