Pimcore代码在哪里 [英] Pimcore where does code go

查看:158
本文介绍了Pimcore代码在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有示例均显示随机的pimcore代码;但是,我没有找到代码去向的解释-或完整的示例.我不在cms上使用pimcore.我只对对象管理感兴趣.我试图写的代码是导出对象,例如转换为csv或xml.

All the examples show random pimcore code; however, I have found no explanation of where the code goes - or a complete example. I do not use pimcore for the cms. I am only interested in the object management. The code I am trying to wrte is to export objects e.g. into csv or xml.

谢谢〜

推荐答案

您可以按照Johan的建议创建一个插件,但是一种更快的方法是将文件放入/website/lib/Website文件夹.此文件夹已经添加到自动装带器中,因此您无需执行其他任何操作.

You can either create a plugin as suggested by Johan, but a quicker way is to just put the files into the /website/lib/Website folder. This folder is already added to the autoloader so you don't need to do anything else.

例如,在/website/lib/Website文件夹下创建具有以下内容的ObjectExporter.php:

For example create an ObjectExporter.php under /website/lib/Website folder with this content:

<?php
namespace Website;

class ObjectExporter
{
    public function exportObjects()
    {
        // Your code
    }
}

然后,您可以在控制器操作或CLI脚本中实例化此类.控制器操作位于/website/controllers文件夹中,需要通过http调用它们: http://localhost?controller = default& action = default

Then you can either instantiate this class in your controller action or in a CLI script. Controller actions are within /website/controllers folder and they need to be called through http: http://localhost?controller=default&action=default

示例:/website/controllers/DefaultController.php

Example: /website/controllers/DefaultController.php

<?php
class DefaultController extends Website_Controller_Action {
    public function defaultAction () {
        $this->disableViewAutoRender();

        $objectExporter = new Website\ObjectExporter();
        $objectExporter->exportObjects();
    }
}

(您也可以将整个代码直接添加到操作中,但这将是一个难看的解决方案,这当然要视情况而定)

(You could also add your whole code directly into action, but that would be a bit ugly solution, it of course depends)

但是,执行此类任务的更好,最快的方法是使用CLI脚本. 我喜欢使用/website/var/cli文件夹(您需要手动创建,但是默认情况下.htaccess中不包含/website/var文件夹,这使得在这种情况下很实用).

But better and quickest way to approach such tasks is with the CLI scripts. I like to use the /website/var/cli folder (you need to create it manually, but the /website/var folder is excluded in .htaccess by default which makes it practical for such use cases).

示例:/website/var/cli/export-objects.php

Example: /website/var/cli/export-objects.php

<?php
$workingDirectory = getcwd();
chdir(__DIR__);
include_once("../../../pimcore/cli/startup.php");
chdir($workingDirectory);

$objectExporter = new Website\ObjectExporter();
$objectExporter->exportObjects();

然后通过在命令行中发出以下命令来运行它:

Then just run it by issuing this command in your command line:

php website/var/cli/export-objects.php

如果您希望向Pimcore后端添加特殊的UI元素,则方法是按照Johan的建议构建扩展.

In case you wish to add special UI elements to the Pimcore backend, the way to go is with building an extension as suggested by Johan.

伊戈尔

这篇关于Pimcore代码在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆