legow / zend-view-csvstrategy
CSV View strategy for the zend-view lib
Installs: 1 404
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
- psr/container: ^1.0
- zendframework/zend-modulemanager: ^2.8
- zendframework/zend-servicemanager: ^3.1
- zendframework/zend-view: *
Requires (Dev)
- phpunit/phpunit: ^5.6
- squizlabs/php_codesniffer: ^3.3
This package is not auto-updated.
Last update: 2025-01-04 21:41:50 UTC
README
zend-view-csvstrategy
CsvStrategy extension for zendframework/zend-view
How It Works?
- Configure the CsvStrategy to the ViewManager in
module.config.php
<?php return [ 'view_manager' => [ 'template_path_stack' => [ __DIR__ . '/../view', ], 'template_map' => [ 'export/csv' => __DIR__.'/../view/refuels/index/export.pcsv' ], 'strategies' => [ View\Strategy\CsvStrategy::class ] ] ]
- Create csv view file as
export.pcsv
<?php foreach($this->data as $row) { echo implode($row, ';').PHP_EOL; }
- Use it in controller actions
<?php namespace Test; use LegoW\View\Model\CsvModel; class TestController extends AbstractActionController { public function indexAction() { $view = new CsvModel(); $view->setTerminate(true) ->setVariables([ "data" => [ range(1,26), range('a','z') ] ]); return $view; } }