Example #1
0
 /**
  * Processes a view script and returns the output.
  *
  * @param  string|ModelInterface $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values Values to use during rendering
  * @return string The script output.
  */
 public function render($nameOrModel, $values = null)
 {
     /** @var  $nameOrModel \Stjornvisi\View\Model\CsvModel */
     $csv = $nameOrModel->getData();
     /** @var $csv \Stjornvisi\Lib\Csv */
     $string = implode(",", array_map(function ($data) {
         return "\"" . addslashes($data) . "\"";
     }, $csv->getHeader())) . PHP_EOL;
     foreach ($csv as $item) {
         $string .= implode(",", array_map(function ($data) {
             return "\"" . addslashes($data) . "\"";
         }, $item));
         $string .= PHP_EOL;
     }
     return $string;
 }