不理解php-joomla文件中引用的$this


dont understand reference $this in php joomla file

我只是在学习joomla编码。在里面http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Example_of_a_frontend_update_function我看到了一个引用$this->表单,也看到了下面的复制代码。

我的初学者问题是:$this与什么有关?

代码站点/views/uphelloworld/tmpl/default.php:

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.keepalive');
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.tooltip');
?>
<h2>Update the Hello World greeting</h2>
<form class="form-validate" action="<?php echo JRoute::_('index.php'); ?>" method="post" id="updhelloworld" name="updhelloworld">
            <fieldset>
            <dl>
                <dt><?php echo $this->form->getLabel('id'); ?></dt>
            <dd><?php echo $this->form->getInput('id'); ?></dd>
Joomla模板(视图(中的

$this是指JView类。JView类附带了许多标准选项,可以在您提供的文档中找到。此外,可以添加一个扩展JView的视图,因此,那里的方法/属性也将通过$this在模板中可用。

http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Adding_a_view_to_the_site_part

根据该文档,您可以看到控制器如何渲染视图,以及如何创建自定义视图类。

你的问题的确切答案也在那里:

这个模板文件将包含在JView类中。因此这里,$this指的是HelloWorldViewHelloWorld类。

$this->是来自Joomla的上下文。

它包含在某个地方,所以$this被引用到包含该文件的类。

在这种情况下,它将是当前页面的上下文,该页面被构建为一个类。