Saturday, 15 August 2015

php - PhpRenderer not rendering my view script from console route -



php - PhpRenderer not rendering my view script from console route -

i've created console route on zf2 application dispatch email via command line. in action creating new phprenderer specified in documentation (http://framework.zend.com/manual/2.0/en/modules/zend.view.renderer.php-renderer.html) render email template (replace variables etc) , dispatch it.

here code using:

$renderer = new \zend\view\renderer\phprenderer(); $resolver = new \zend\view\resolver\templatemapresolver(); $resolver->setmap(array( 'mailtemplate' => $config['template'] )); $renderer->setresolver($resolver); $model = new \zend\view\model\viewmodel(); $model->settemplate('mailtemplate'); $model->setvariables(array( 'recipient' => 'foo@bar.com' )); $emailbody = $renderer->render($model);

however seems phprenderer not render php in .phtml file. exact same code works correctly if execute in normal http request.

could help me out this?

i suspect it's because haven't set right path resolver.

for reference, approach took:

// render html , text bodies $basepath = realpath(__dir__'/../../../view/emails'); $htmlfilename = 'body.html.phtml'; $txtfilename = 'body.txt.phtml'; $renderer = new phprenderer(); $renderer->resolver()->addpath($basepath); $sm = $this->getservicemanager(); $renderer->sethelperpluginmanager($sm->get('viewhelpermanager')); $model = new viewmodel(); $model->setvariable('name', $user->getname()); $model->settemplate($txtfilename); $textcontent = $renderer->render($model); $model->settemplate($htmlfilename); $htmlcontent = $renderer->render($model);

php zend-framework2

No comments:

Post a Comment