Created
May 28, 2013 08:53
-
-
Save kaiohken1982/5661445 to your computer and use it in GitHub Desktop.
ZF2 PhpRenderer Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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