1

不是 modx 的忠实粉丝,但遗憾的是它是我们在工作中使用的。

我无法在 modx evolution (1.0.5) 中保存修改后的模板变量。

在我的插件中,使用 OnBeforeDocFormSave 事件调用,我这样做是为了获取和修改电视:

//include global variables
global $content,$default_template,$tmplvars;

$foo = $tmplvars[$TV_ID][1] . "bar";

$tmplvars[$TV_ID][1] = $foo;

这似乎不起作用。$foo 已设置,但电视未保存。

$TV_ID 是我所追求的模板变量的资源 ID。

有很多方法可以通过 API 调用获取电视,但如何在保存之前对其进行修改?

任何帮助表示赞赏。

4

2 回答 2

1

此解决方案似乎有效:

由 OnBeforeDocFormSave 事件上的插件调用

//include global variables
global $content,$default_template,$tmplvars;

$foo = $tmplvars[$TV_ID][1] . "bar";

$tmplvars[$TV_ID][0] = $TV_ID; //added this line
$tmplvars[$TV_ID][1] = $foo;

其中 $TV_ID 是您尝试修改的模板变量的 ID。

于 2011-09-01T16:32:42.057 回答
1

您在使用 Evo 或 Revo 吗?

我使用 OnWebPageComplete 事件上的插件更新页面计数器,如下所示:

<?php

$docID = $modx->resource->get('id'); //get the page id

$tvId = 9; //the tv id I want to change

$tv = $modx->getObject('modTemplateVar',$tvId); // get the obj.

$tv->setValue($docID, $tv->getValue($docID) + 1 ); // set it's new value

$tv->save(); // save the new value

-肖恩

于 2011-08-31T16:58:28.437 回答