如何将导出到 csv 与 octobercms 中的后端列表集成
How to integrate exporting to csv with backend list in octobercms
我是OctoberCMS 的初学者,我打算在后端列表中使用导出功能。我在 octobercms 的后端阅读了关于 importing and exporting 的文档。
但我不知道如何使用这个功能,我想知道以下内容。
- 如何在后端列表中添加导出按钮。
- 如何将导出与后端列表集成。
希望得到您的帮助。
谢谢。
步骤[这里我们需要导出TimeLog
模型数据]
1. Add this lines to your controller
// if you have more behaviors add this one as extra
public $implement = [
'Backend.Behaviors.ImportExportController',
];
// your config
public $importExportConfig = 'config_import_export.yaml';
2. Now inside your config config_import_export.yaml
export:
title: Export TimeLog
modelClass: HardikSatasiya\TimeTracker\Models\TimeLogExport
list: $/hardiksatasiya/timetracker/models/timelog/columns.yaml
redirect: hardiksatasiya/timetracker/timelog
3. $/hardiksatasiya/timetracker/models/timelog/columns.yaml
we will use default list model fields so no changes here.
4. Now you need to put file export.htm
in views directory with this content
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->exportRender() ?>
</div>
<div class="form-buttons">
<button
type="submit"
data-control="popup"
data-handler="onExportLoadForm"
data-keyboard="false"
class="btn btn-primary">
Export records
</button>
</div>
<?= Form::close() ?>
5. Now you need any button/ menu
which can redirect you to export
action of your controller, as we are implementing import-export
behavior our controller can have export
and import
actions.
Next
so you can point to this url an you can see export screen http://localhost/backend/<author_name>/<plugin_name>/<controller_name>/export
OR BETTER you can add export button on toolbar which can redirect you to export screen [use this docu to modify your list toolbar https://octobercms.com/docs/backend/lists#adding-toolbar]
如果你喜欢更多默认的东西
您可以按照步骤 1 进行操作,然后在 步骤 2 中使用此设置
export:
useList: true
那么你可以跳过所有其他配置
last step you just need to point to export url -> http://localhost/backend/<author_name>/<plugin_name>/<controller_name>/export
to generate CSV no question asked that url will read all info from list config and let you directly download export.csv file
对于多个列表导出和其他内容,请阅读此文档:https://octobercms.com/docs/backend/import-export#list-behavior-integration
如有其他问题请补充评论
我是OctoberCMS 的初学者,我打算在后端列表中使用导出功能。我在 octobercms 的后端阅读了关于 importing and exporting 的文档。
但我不知道如何使用这个功能,我想知道以下内容。
- 如何在后端列表中添加导出按钮。
- 如何将导出与后端列表集成。
希望得到您的帮助。 谢谢。
步骤[这里我们需要导出TimeLog
模型数据]
1. Add this lines to your controller
// if you have more behaviors add this one as extra
public $implement = [
'Backend.Behaviors.ImportExportController',
];
// your config
public $importExportConfig = 'config_import_export.yaml';
2. Now inside your config
config_import_export.yaml
export:
title: Export TimeLog
modelClass: HardikSatasiya\TimeTracker\Models\TimeLogExport
list: $/hardiksatasiya/timetracker/models/timelog/columns.yaml
redirect: hardiksatasiya/timetracker/timelog
3.
$/hardiksatasiya/timetracker/models/timelog/columns.yaml
we will use default list model fields so no changes here.
4. Now you need to put file
export.htm
in views directory with this content
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->exportRender() ?>
</div>
<div class="form-buttons">
<button
type="submit"
data-control="popup"
data-handler="onExportLoadForm"
data-keyboard="false"
class="btn btn-primary">
Export records
</button>
</div>
<?= Form::close() ?>
5. Now you need
any button/ menu
which can redirect you toexport
action of your controller, as we are implementingimport-export
behavior our controller can haveexport
andimport
actions.
Next
so you can point to this url an you can see export screen
http://localhost/backend/<author_name>/<plugin_name>/<controller_name>/export
OR BETTER you can add export button on toolbar which can redirect you to export screen [use this docu to modify your list toolbar https://octobercms.com/docs/backend/lists#adding-toolbar]
如果你喜欢更多默认的东西
您可以按照步骤 1 进行操作,然后在 步骤 2 中使用此设置
export:
useList: true
那么你可以跳过所有其他配置
last step you just need to point to export url ->
http://localhost/backend/<author_name>/<plugin_name>/<controller_name>/export
to generate CSV no question asked that url will read all info from list config andlet you directly download export.csv file
对于多个列表导出和其他内容,请阅读此文档:https://octobercms.com/docs/backend/import-export#list-behavior-integration
如有其他问题请补充评论