Homepage
Main navigation
Main content
Additional information
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Winter CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
Here's a few tricks to use the `ImportExportController`: Note: In this example, my controller is called `Invoices` and my model `Invoice`. create a seperate list definition to export your records in your controller: Add this to your controller: ```php public $implement = [ 'Backend.Behaviors.FormController', 'Backend.Behaviors.ImportExportController', 'Backend.Behaviors.ListController', ]; public $listConfig = [ 'list' => 'config_list.yaml', # your default list definition 'export' => [ 'list' => '$/author/plugin/models/invoice/export_columns.yaml', 'modelClass' => 'Author\Plugin\Models\Invoice', ], ]; public $importExportConfig = 'config_import_export.yaml'; ``` Use this config_import_export.yaml (note the use of `raw: true`): ```yaml export: fileName: invoices_export.csv useList: raw: true definition: export ``` And add this to your controller's `_list_toolbar.php`: ``` <a href="<?= Backend::url('author/plugin/invoices/export') ?>" class="wn-icon-download"> Export </a> ``` You can also modify the query for your export list by adding this method to your controller: ```php public function listExtendQuery($query, $definition) { if ($definition === 'export') { return $query->where('status', 'complete'); } } ``` And modify the records by adding this method to your controller: ```php public function listExtendRecords($records, $definition = null) { if ($definition === 'export') { foreach ($records as $record) { ... } } } ```
References
Add additional online resources to your trick
×
Name
URL
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline