我知道周围有几个类似的主题,但我阅读并尝试了其中的大部分内容,但仍然无法弄清楚如何做到这一点。
我在 Joomla 2.5 中编写了一个组件,到目前为止它可以工作。我有不同的 View ,我可以使用 controller.php 加载 View 。
其中一个 View 显示了我的数据库中的一个表(关于团队的数据)。
现在我想拥有相同 View 的另一个布局,它将数据库表显示为表单,以便可以更改内容。
这是文件结构:
观看次数/
- 团队/
- - tmpl/
- - - default.php
- - - 修改.php
--view.html.php
那是在 view.html.php 文件之外:
...
// Overwriting JView display method
function display($tpl = null) {
...
$this->setLayout('modify');
echo $this->getLayout();
// Display the view
parent::display($tpl);
}
我尝试了 setLayout、$tpl = ...、default_modify.php 等的不同组合。
但我总是得到默认布局或一些错误,如“找不到布局修改”
我用 .../index.php?option=com_test&task=updateTeams 加载网站
controller.php 看起来像这样:
function updateTeams(){
$model = $this->getModel('teams');
$view = $this->getView('teams','html');
$view->setModel($model);
$view->display();
}
最佳答案
我有一个类似的问题,我创建了某种用户配置文件 View ,并希望他们能够编辑字段而不必为其创建新模型(会有类似的功能,讨厌冗余......)。对我有用的是简单地调用这样的布局:
index.php?option=com_mycomponent&view=myview& layout=edit (在您的情况下,“编辑”将是“修改”)
要做到这一点,我没有触及 view.html.php(我一开始做到了,但我没有必要。)。而且您也不需要使用 Controller 。如果要加载修改 View ,只需在常规 View 中添加一个按钮,链接到修改布局。无需更改任何其他内容。
我碰巧写了一篇关于它的博客文章,如果你想看看:http://violetfortytwo.blogspot.de/2012/11/joomla-25-multiple-views-one-model.html
希望这可以帮助。
关于php - 更改 Joomla 2.5 中的 View 布局,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18817338/