php - How to use ViewManager in CLI application? -


a have simple zend framework 2 console application. controller actions generate files (html, markdown, json etc). example:

class examplecontroller extends abstractactioncontroller {     public function createaction()     {         // create $contents...         file_put_contents('./file.html', $contents);         return 'file created';     } } 

i use viewmanager create files based on templates using view helpers. added settings module.config.php:

return [     // ...     'view_manager' => [         'template_path_stack' => [             __dir__ . '/../view',         ],     ], ]; 

but have no idea next. how use viewmanager in cli application?

you can call viewrenderer service controller or factory (with injected servicelocator):

$view = $this->getservicelocator()->get('viewrenderer'); 

with $view, can render viewmodel object.

$content = $view->render($viewmodel); 

you can define template on viewmodel settemplate().


Comments