-1

I am trying to use the \Zend\View components for page and form rendering, without the full framework stack.

Using composer, i have installed zendframework\zend-view 2.6

After some research, i have found the following code examples to use views standalone:

$resolver = new \Zend\View\Resolver\TemplatePathStack();
$resolver->addPath('/path/to/view/dir');

$renderer = new \Zend\View\Renderer\PhpRenderer();
$renderer->setResolver($resolver);

$viewModel = new \Zend\View\Model\ViewModel(); 
$viewModel->setTemplate('index.phtml');
$viewModel->setVariable('userName', 'John Doe');

echo $renderer->render($viewModel)

But it is generating the following exception:

Catchable fatal error: Argument 1 passed to Zend\ServiceManager\AbstractPluginManager::__construct() must be an instance of Zend\ServiceManager\ConfigInterface, instance of Zend\ServiceManager\ServiceManager given, called in C:\workspace\project\vendor\zendframework\zend-view\src\HelperPluginManager.php on line 250 and defined in C:\Program Files (x86)\Zend\ZendServer\data\libraries\Zend_Framework_2\default\library\Zend\ServiceManager\AbstractPluginManager.php on line 62

What am i missing? Or are there any other resources for getting zf2 views to run standalone?

John Crest
  • 201
  • 1
  • 4
  • 24
  • Not giving an answer, but here is how i used `Zend\View` in silex microframework app https://gist.github.com/Xerkus/a8c6fa3b622632c018ae4986d8c11ba4 – Xerkus Mar 30 '16 at 10:10
  • Thanks for the reply - an interesting read but i cannot see any different configuration or understanding of how to use zend-view standalone from your example. Is it with zend-view 2.6? – John Crest Mar 30 '16 at 20:50

1 Answers1

0

It may help if you set terminal true, something like this:

$viewModel->setTemplate('index.phtml');
$viewModel->setTerminal(true); // <== I mean add this line here
$viewModel->setVariable('userName', 'John Doe'); code here