joomla将视图添加到另一个视图 [英] joomla add view into another view
问题描述
我正在使用joomla MVC,我想构建一个表单,该表单具有不同的选项卡,这些选项卡是表单的不同部分,其中包含输入.我需要包括一些其他表格所共有的标签.
Im using joomla MVC and I want to build a form that has different tabs which are different sections of the form with inputs in it. There are some tabs that are common to other forms that I need to include.
我希望能够从单独的文件或视图中加载此通用内容,因此我没有重复的代码,而且当我需要对表单进行更改时更容易,因此我不必在所有表单中都做形式.就像在另一个视图中显示一个视图一样.
I would like to be able to load this common content from a separate file or view so i dont have duplicate code, plus is easier when I need to do a change to the form so I dont have to do it in all the forms. It's like displaying a view inside another view.
有没有办法做到这一点?
Is there a way to accomplish this?
推荐答案
一个Joomla!为视图提供loadTemplate
方法.
A Joomla! provides the loadTemplate
method to views.
因此,如果您当前正在为布局edit
加载的tmpl
文件(即tmpl/edit.php
),则可以调用$this->loadTemplate('tab1');
和Joomla!将在与edit.php
相同的视图中加载tmpl/edit_tab1.php
文件.
So if you're currently in a tmpl
file loaded for layout edit
(ie. tmpl/edit.php
) you can call $this->loadTemplate('tab1');
and Joomla! will load the tmpl/edit_tab1.php
file in the same view as your edit.php
.
在同一视图中,如果您想包含说出tmpl/other_tab1.php
的内容,则必须将布局临时设置为 other (例如).在 Run 模板中的一个组件中,我们需要 Edit 模板中的标签,因此我们使用:
In that same view if you wanted to include say tmpl/other_tab1.php
you would have to temporarily set the layout to other, eg. in one of our components during the Run template we need a tab from the Edit template, so we use:
<?php $this->setLayout('edit'); // This is ugly
echo $this->loadTemplate('plan');
$this->setLayout('run'); ?>
要一起从另一个视图加载模板,我认为您必须暂时改写view
值,加载模板然后恢复视图.例如.
To load a template from another view alltogether, I think you would have to temporarily over-ride the view
value, load the template then restore the view. eg.
$jinput = JFactory::getApplication()->input;
$jinput->set('view', 'other');
$this->loadTemplate('tab2');
$jinput->set('view', 'original');
NB:这最后一点我没有时间测试,但应该可以.
这篇关于joomla将视图添加到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!