gpt4 book ai didi

php - 在 Joomla 2.5 中更改 View 布局

转载 作者:可可西里 更新时间:2023-11-01 00:45:59 25 4
gpt4 key购买 nike

我知道周围有几个类似的主题,但我阅读并尝试了其中的大部分内容,但仍然不知道如何做到这一点。

我在 Joomla 2.5 中编写了一个组件,到目前为止它可以正常工作。我有不同的 View ,我可以使用 controller.php 加载 View 。其中一个 View 显示了我的数据库中的一个表(关于团队的数据)。

现在我想要同一个 View 的另一个布局,它将数据库表显示为一个表单,以便可以更改内容。

这是文件结构:

观看次数/
- 团队/
- - tmpl/
- - - 默认.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com