教程栏目

joomla中文网出品的官方教程

关于控制器的display方法是本节需要了解的重点。我们今天来尝试分析一下这个神秘的方法。

 

首先看一下这个方法的源代码:

 

public function display($cachable = false, $urlparams = array())
{
$document = JFactory::getDocument();
$viewType = $document->getType();
$viewName = $this->input->get('view', $this->default_view);
$viewLayout = $this->input->get('layout', 'default', 'string');

$view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout));

// Get/Create the model
if ($model = $this->getModel($viewName))
{
// Push the model into the view (as default)
$view->setModel($model, true);
}

$view->document = $document;

$conf = JFactory::getConfig();

// Display the view
if ($cachable && $viewType != 'feed' && $conf->get('caching') >= 1)
{
$option = $this->input->get('option');
$cache = JFactory::getCache($option, 'view');

if (is_array($urlparams))
{
$app = JFactory::getApplication();

if (!empty($app->registeredurlparams))
{
$registeredurlparams = $app->registeredurlparams;
}
else
{
$registeredurlparams = new stdClass;
}

foreach ($urlparams as $key => $value)
{
// Add your safe url parameters with variable type as value {@see JFilterInput::clean()}.
$registeredurlparams->$key = $value;
}

$app->registeredurlparams = $registeredurlparams;
}

$cache->get($view, 'display');
}
else
{
$view->display();
}

return $this;
}

这个函数的功能提供一个MVC的基础架构的默认实现。大多数情况下我们需要自己实现。这个函数提供两个参数,一个是$cachable ,主要是控制是否需要缓冲输出。另外一个是¥urlparams 。这是一个数组,用来存储url中的参数的。

看看这个函数到底在干嘛

首先,它获得一个文档对象,也就是JDocumentHEML对象,然后获得视图的类型,一般情况下是HTML.也可以是PDF等等。 获得到视图,获得到视图所需要的布局。然后由视图获得相应的模型。

在视图中有一个document对象。系统通过获得全局配置,判断是否需要启用缓存。最后调用视图的display方法。

作者: 樱木花道

Joomla程序员,从J1.5到J4.x始终都在做Joomla相关开发定制工作,有超过10年行业经验,国内Joomla扩展开发商ZMAX团队的核心成员

作者网站:ZMAX程序人

评论 (0)

  • 最新在前
  • 最佳在前

第1章 Joomla入门教程

第3章 C计划

第5章 E计划

第6章 H计划

第7章 G计划

第9章 运行环境

第11章 主从与集群

第12章 模块开发

第13章 插件开发

第14章 j2.x组件开发教程

第15章 页面定制教程

第16章 页面构造器

第17章 joomla升级

第18章 其他系统迁移

第19章 流量翻倍计划