教程栏目

joomla中文网出品的官方教程

在本节中我们将再次了解一下joomla组件的大体执行流程。

 在进行下面的讲解之前,我想谈一下整个组件的执行流程。

 

 有 了这个流程图之后,基本上对joomlaMVC的调用关系就清楚多了。在进行下面的操作之前,我把先前的一些视图类和模型类都重命名了。比喻将views 下面的guestbook文件夹改为postmessage ,意思是提交留言页面,将models文件夹下的guestbook.php也改为postmessage.php。当然还对类名做了一些修改(不然执行 出错)。

如果你能顺利的完成对视图的重命名,那么你对joomla的MVC就理解了。

2013-11-02修改:

需要对上面的流程图做一些补充:

看了一下libraries\joomla\application\componet\controlelr.php文件中的JController类的实现。其中display方法的实现代码如下:

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

		$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->assignRef('document', $document);

		$conf = JFactory::getConfig();

		// Display the view
		if ($cachable && $viewType != 'feed' && $conf->get('caching') >= 1)
		{
			$option = JRequest::getCmd('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;
	}
 

在 上面的代码,我们可以清楚的看到JController类是在display方法中实例化模型类和视图类的。因此,当我们设定了一个视图类的时候,必须要 执行父类的display方法,这样系统才能实例化模型类 和视图类。以后你会看到在控制器中经常出现parent::display()方法的调用。

下一节我们要完成显示留言页面。敬请期待!

评论 (0)

  • 最新在前
  • 最佳在前

第1章 Joomla入门教程

第3章 C计划

第5章 E计划

第6章 H计划

第7章 G计划

第9章 运行环境

第11章 主从与集群

第12章 模块开发

第13章 插件开发

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

第15章 页面定制教程

第16章 页面构造器

第17章 joomla升级

第18章 其他系统迁移

第19章 流量翻倍计划