简体   繁体   English

如何使用MODX处理器向数据库添加许多元素

[英]How to add many elements to database with MODX-processor

I have a file-uploading-processor with array output. 我有一个带阵列输出的文件上传处理器。 How I can add this array to database? 如何将此数组添加到数据库?

That's my processor's code: 这是我的处理器代码:

class ModCLJsonUploadProcessor extends modProcessor {
    public $languageTopics = ['modcl'];

    public function process() {
        $file = fopen($_FILES['json-file']['tmp_name'], 'r');
        $json = fread($file, $_FILES['json-file']['size']);
        $objs = json_decode($json);
        $english = array();
        for ($i = 0; $i < count($objs); $i++) {
            $english[$i] = $objs[$i]->{'name'};
        }

        return $this->success($english);
    }
}

return 'ModCLJsonUploadProcessor';

I tried to use the native modObjectCreateProcessor, but it does not support arrays. 我尝试使用本机modObjectCreateProcessor,但它不支持数组。

In order to save items into the database using a processor, the best practice would be to create a schema and save the given data as objects in the database. 为了使用处理器将项目保存到数据库中,最佳做法是创建模式并将给定数据保存为数据库中的对象。 This allows you to then later retreive the items (objects) in other processors or snippets using xPDO. 这允许您稍后使用xPDO检索其他处理器或片段中的项目(对象)。

For a basic explenation/how to on creating a schema and interacting with the custom objects have a look at the "Developing an extra in MODX Revolution" doc here 对于基本explenation /如何在创建模式,并与自定义对象进行交互有一个看看“在镆铘革命发展中一个额外的” DOC 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM