I am trying to use ZF2 PhpRenderer without the MVC framework. Currently I am not able to implement everything but wanted to start re-factoring some stuff into a modified version until I am able to implement the whole framework later in life.
I have been trying to use the Programmer’s Reference.
At the top of my tester.php script I have.
use Zend\View\Model\ViewModel,
Zend\View\Renderer\PhpRenderer,
Zend\View\Resolver;
Then later on in the script I have this to start trying to render a script.
$renderer = new PhpRenderer();
$map = new Resolver\TemplateMapResolver(array(
'tester' => __DIR__ . '/tester.phtml',
));
$resolver = new Resolver\TemplateMapResolver($map);
$model = new ViewModel();
$model->setVariable('foo', 'bar');
$model->setTemplate('tester');
echo $renderer->render($model);
The error I get is this
Unable to render template “tester”; resolver could not resolve to a file’ in /home/lumberjacked/workspace/www/vendor/zf2/library/Zend/View/Renderer/PhpRenderer.php on line 461
Any help would be awesome.
I found the solution and its pretty simple. After declaring your $resolver you have to set it in the $renderer.
I found this in the constructor of the renderer calling this method.