Skip to content

adamturcsan/zend-view-csvstrategy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

zend-view-csvstrategy

CsvStrategy extension for zendframework/zend-view

How It Works?

  1. 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
                ]
            ]
        ]
  2. Create csv view file as export.pcsv
        <?php 
    
        foreach($this->data as $row) {
            echo implode($row, ';').PHP_EOL;
        }
  3. 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;
            }
        }

About

CsvStrategy extension for zendframework/zend-view

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages