Skip to content

Instantly share code, notes, and snippets.

@kaiohken1982
Created May 28, 2013 08:53
Show Gist options
  • Save kaiohken1982/5661445 to your computer and use it in GitHub Desktop.
Save kaiohken1982/5661445 to your computer and use it in GitHub Desktop.
ZF2 PhpRenderer Service
use Zend\View\Model\ViewModel;
[...]
// within the constructor
$this->viewmodel = new ViewModel();
$this->viewmodel->setVariable('myobj', $this); // object assigned to view model will be available
// within the view script using $this->myobj
[...]
public function render()
{
$this->viewmodel->setTemplate('myobj/mytemplate'); // mymodule/view/myobj/mytemplate.phtml
// getView() return an instance of 'Zend\View\Renderer\PhpRenderer'
// you can set using sl in the service config $myobj->setView($sl->get('Zend\View\Renderer\PhpRenderer'));
return $this->getView()->render($this->viewmodel);
}
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment