 
      
      
    
	关于控制器的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方法。


评论 (0)