Php 第二个运行处理器返回第一个处理器的响应

Php 第二个运行处理器返回第一个处理器的响应,php,modx-revolution,Php,Modx Revolution,您好,提前谢谢您的帮助! 所以问题是: 我在插件中运行了两个不同的处理器——我正在创建一个用户(security/user/create)和其他信息对象(我的自定义类)。 问题是第二个处理器总是返回第一个处理器的响应。如果我删除第一个处理器调用,就可以了。当我尝试在第二个处理器中执行相同操作时,问题是相同的。因此代码: $response = $modx->runProcessor('security/user/create',$_REQUEST); $resp=$modx->run

您好,提前谢谢您的帮助! 所以问题是: 我在插件中运行了两个不同的处理器——我正在创建一个用户(security/user/create)和其他信息对象(我的自定义类)。 问题是第二个处理器总是返回第一个处理器的响应。如果我删除第一个处理器调用,就可以了。当我尝试在第二个处理器中执行相同操作时,问题是相同的。因此代码:

$response = $modx->runProcessor('security/user/create',$_REQUEST);
$resp=$modx->runProcessor('mgr/userdata/create',$_REQUEST,array("processors_path"=>$custom_path));
$modx->log(MODx::LOG_LEVEL_ERROR,print_r($resp->response,true));
返回:

[2014-11-21 01:01:44] (ERROR @ /index.php) Array ( [success] => [message] => [total] => 1 [errors] => Array ( [0] => Array ( [id] => username [msg] => This username is already used! ) ) [object] => Array ( ) ) [2014-11-21 01:01:44](ERROR@/index.php)数组 ( [成功]=> [信息]=> [总数]=>1 [错误]=>数组 ( [0]=>阵列 ( [id]=>用户名 [msg]=>此用户名已被使用! ) ) [对象]=>数组 ( ) )
它是一种什么样的巫术?如何使它工作?

你确定它会进入第二个处理器吗?尝试同时记录以下两项:

$response = $modx->runProcessor('security/user/create',$_REQUEST);
$modx->log(MODx::LOG_LEVEL_ERROR,print_r($response->response,true));

$resp=$modx->runProcessor('mgr/userdata/create',$_REQUEST,array("processors_path"=>$custom_path));
$modx->log(MODx::LOG_LEVEL_ERROR,print_r($resp->response,true));

MODX上的处理器使用公共
$MODX->error
对象。在日志中,用户创建时出现错误。第二个处理器捕获它,但无法成功完成

这都是因为$modx->error对于一个流中的所有处理器来说都是常见的。最简单的方法是在第一次处理器调用后使用
$modx->error->reset

但如果我们再深入一点呢

是否要为他创建用户和相关数据?好啊但如果用户创建成功,而您的自定义数据创建失败怎么办?最终我们得到了不一致的数据。这真让人头痛

对我来说,最好的方法是创建扩展
安全性/user/create processor
的自定义处理器。在保存之前有一个特殊的
方法。因此,您可以了解用户创建何时成功,然后创建自定义数据。真是太棒了。
示例(这是我的一个项目中的处理器,与用户创建无关,但含义相同):

class modWebOrdersOrdersBulkComplectationCompleteProcessor extends modWebOrdersOrdersUpdateProcessor{


public function beforeSave(){

    $canSave = parent::beforeSave();
    if($canSave !== true){
        return $canSave;
    }    

    // if we are here user creating has no errors.

    // method for my additional logic. If i have errors there user won't be created
    $ok = $this->transactionCreate();
    if($ok !== true){
        return $ok;
    }


    return true;
}

protected function transactionCreate(){          

    // i'm usually works with related objects and use especially aggregates/composites relations. So if user has related data profile it will be saved when `save` method will be called for $this->object.

    $_Transaction = $this->modx->newObject('BillingProductTransaction', array(
        'createdby' => $this->modx->user->id,
        'cause'=>   2
    ));

    $this->object->Transaction = $_Transaction;

    // but anyway you can run your subprocessor there. But there are some cons
    // 1. $this->modx->error is common. if you make multiple runProcessor call there you can get some weird problems with logic. (error->reset() is hack not feature)
    // 2. when your project architecture grows logic based on relations becomes more maintainable.

    return true;
}