integrate import export csv with backend list in octobercms
To be able to Import and Export data from database is crutial part for data anylysis and migration. OctoberCMS has built in support for Import/Export but it need to be done manually. You need to have basic coding experiance to implement it.
Do not worry we will cover all start to end with example code in this article to make it really easy for you to integrate Import and Export in your list.
First thing first you can siply use OctoberCMS Builder Plugin
to create list of your data.
Now lest's start integrating Import and Export in your backend listing.
In your controller file you need to add basic code snippet
- ImportExportController Behaviout to add action/routes
- Configration file to tell how to Import and Export Data
// if you have more behaviors add this one as extra
public $implement = [
'Backend.Behaviors.ImportExportController',
];
// your config file
public $importExportConfig = 'config_import_export.yaml';
export:
useList: true
When you use
useList: true
option it will fetch all the details from the list and
Now you need to add button or menu
which can redirect you to export action
of your controller, as we already implemented import-export behavior in our controller.
http://localhost/backend/<author_name>/<plugin_name>/<sontroller_name>/export
It will generate CSV no question asked that url will read all info from list config and let you directly download export.csv file
export:
title: Export TimeLog
modelClass: HardikSatasiyaTimeTrackerModelsTimeLogExport
list: $/hardiksatasiya/timetracker/models/timelog/columns.yaml
redirect: hardiksatasiya/timetracker/timelog
Now you need to create
export.htm
along side in yourcontroller
file.
<?= 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() ?>
Now you can simple add Import and Export menu items in side menu bar. which can redirect user to respective URL.
http://localhost/backend/<author_name>/<plugin_name>/<sontroller_name>/import
http://localhost/backend/<author_name>/<plugin_name>/<sontroller_name>/export
In this way you can have more control over importing and exporting data.
If you have any condfusion or question please add comments.
Related Questions
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS