Skip to content

Commit

Permalink
refactor: use a sub-array with actual data versus a weird key/value s…
Browse files Browse the repository at this point in the history
…etup.
  • Loading branch information
josegonzalez committed Jun 27, 2017
1 parent bccaeb6 commit 2c1602e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions docs/_partials/pages/index/download-format-links.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The ``scaffold.index_formats`` configuration key can be used to customize
page, and can be used to expose the paginated data in JSON, XML, or other
formats. The output of each format can be customized to your specifications.

The ``scaffold.index_formats`` option takes an array of data, where the "key" is
the url and the value is the title to use for the link.
The ``scaffold.index_formats`` option takes an array of download format data.
Each sub-array should contain ``title`` and ``url`` parameters.

.. code-block:: php
Expand All @@ -18,8 +18,14 @@ the url and the value is the title to use for the link.
// currently applied filters
$action = $this->Crud->action();
$action->config('scaffold.index_formats', [
Router::url(['_ext' => 'json', '?' => $this->request->query]) => 'JSON',
Router::url(['_ext' => 'xml', '?' => $this->request->query]) => 'XML',
[
'title' => 'JSON',
'url' => ['_ext' => 'json', '?' => $this->request->query]
],
[
'title' => 'XML',
'url' => Router::url(['_ext' => 'xml', '?' => $this->request->query])
],
]);
Download links are displayed near the bottom-left of the index page and will
Expand Down Expand Up @@ -78,7 +84,10 @@ can be modified to add a CSV Download Link.
}
$this->Crud->action()->config('scaffold.index_formats', [
Router::url(['_ext' => 'csv', '?' => $this->request->query]) => 'CSV',
[
'title' => 'CSV',
'url' => ['_ext' => 'csv', '?' => $this->request->query]
],
]);
return $this->Crud->execute();
}
4 changes: 2 additions & 2 deletions src/Template/Element/index/download_formats.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ if (empty($indexFormats)) {
?>
<div class="download-links">
<?= __d('crud', 'Download') ?>:
<?php foreach ($indexFormats as $formatRoute => $formatTitle) : ?>
<?= $this->Html->link($formatTitle, $formatRoute, [
<?php foreach ($indexFormats as $indexFormat) : ?>
<?= $this->Html->link($indexFormat['title'], $indexFormat['url'], [
'target' => '_blank'
]); ?>
<?php endforeach; ?>
Expand Down

0 comments on commit 2c1602e

Please sign in to comment.