I am a beginner of OctoberCMS and I am going to use export feature in backend list. I have read document about importing and exporting in backend of octobercms.
But I am not sure how to use this feature and I want to know followings.
I hope your kind assistance. Thank you.
Steps [here we need to export TimeLog
model data]
Reference : Tutorialmeta.com
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]
what you can do is just follow step 1 then in step 2 use this settings
export:
useList: true
then you can skip all other config
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
for multiple list export and other stuff read this docu: https://octobercms.com/docs/backend/import-export#list-behavior-integration
if any further questions please add comment