将数据存储在与 modx_site_content table 不同的 table 中的独立 MODx 上下文

Separate MODx contexts storing data in separate tables from modx_site_content table

我在 "modx_site_content" table 中拥有其他外部软件正在使用的所有数据。一切都很好——我们 view/add/edit/delete 数据到一个 table 中,供 MODx 和其他 2 个 PHP/JS 脚本使用。但我很想拥有另一个 MODx 和其他脚本都使用的 table。我是否有可能创建新的上下文,例如 "modx_site_content2" table?

这是可能的,但不是真正好的方法。首先,它需要相当多的插件才能弄清楚它是如何工作的。我会尝试做的是(我没有 运行 实例)。并且需要一些摆弄 php 和 sql.

为 onLoadWebDocument 创建插件,检查插件上 $modx->context->key(或那个方向的东西)的上下文键是什么,你有 $modx->resource 对象,你可以实际覆盖它。

因此,接下来使用 url 路径加载资源(您需要将其拆分),这将使用 sql 查询匹配资源的别名。有一个像下面这样的 php 部分:

$res = $modx->query('your_modResource_clone', 214); // 214 is the resource id and the object needs to inherit modResource
$obj = new modResource($modx);
$obj->fromArray($res->toArray()); // Could be that you can actually assign the object directly to line below.
$modx->resource = $obj;

这实际上应该有效,因为对象只是加载而不是渲染。代码可能有点不对(就像说没有任何 运行 个实例)。 modx 也有可能不缓存它。它应该但现在不确定。请注意,您还需要解析 url 以获得正确的 ID,这将使这变得更加困难。但是基本概念就在那里。希望