我正在使用带有插件Login和Babel的 modX Revo 。正如在 Babel 手册中所写的那样,我为两种语言制作了 2 个上下文,使用了 TV 参数并编写了 contextSwitch 插件。它主要类似于手册中示例中的插件。之后,我将插件放在事件 HandleRequest 上。
一切正常,除了登录后切换上下文:如果用户被授权,modX 只显示主页,其他显示 404 页面。我试图在代码中翻找,发现模型 modx 的方法 switchContext(/core/model/modx/modx.class.php 的第 1843 行)返回 false。
public function switchContext($contextKey, $reload = false) {
$switched= false;
if ($this->context->key != $contextKey) {
$switched= $this->_initContext($contextKey, $reload); // RETURNS FALSE
if ($switched) {
if (is_array($this->config)) {
$this->setPlaceholders($this->config, '+');
}
}
}
return $switched;
}
它发生了,因为无法启动上下文(同一文件中同一类的方法_initContext)。这里上下文是正确创建的,当我们要求切换到它时,但 $this->context->checkPolicy('load') 返回 false(在同一文件的 2169 行附近)。
protected function _initContext($contextKey, $regenerate = false) {
// HERE IS EVERYTHING ALLRIGHT
$initialized= false;
$oldContext = is_object($this->context) ? $this->context->get('key') : '';
if (isset($this->contexts[$contextKey])) {
$this->context= & $this->contexts[$contextKey];
} else {
$this->context= $this->newObject('modContext');
$this->context->_fields['key']= $contextKey;
}
if ($this->context) { //HERE TRUE
if (!$this->context->prepare((boolean) $regenerate)) { // HERE TRUE
$this->log(modX::LOG_LEVEL_ERROR, 'Could not prepare context: ' . $contextKey);
} else {
if ($this->context->checkPolicy('load')) { // HERE FALSE - MODX CAN'T DO IT
// .. SOME OTHER modX CODE
所以在那之后我停下来翻找核心。可能有人已经看到类似的东西或者知道 modx Revo 核心很好地回答了为什么 modx 在用户登录时无法切换上下文?
Ps 我尝试为上下文切换插件使用另一个事件 - 但当然这个事件对于插件来说是最正确的。而且我强调 modx 只有在用户登录时才能切换上下文!
更新
我试图编辑一些权限。但是什么都没有发生(我清除了现金并重新登录了所有用户)。这是上下文权限的截图(对不起,非英语,但应该很清楚):
更新 2 权限错误:它们必须全部为 9999 和“list, veiw, load”。但与此同时,当我处于第二个上下文时,我无法登录,就像以前一样。现在我试图找出是否是同样的问题。
更新 3
登录的第二个问题很容易解决:在片段参数中应该有 &contexts=web,eng