joomla 将视图添加到另一个视图中 [英] joomla add view into another view

查看:22
本文介绍了joomla 将视图添加到另一个视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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/edit.php )加载的 tmpl 文件中,您可以调用$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');

注意:最后一点我没有时间测试,但它应该可以工作.

这篇关于joomla 将视图添加到另一个视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆