php - How do I pass data from the controller to the template view in ZF2 using Twig? -
i have problem passing data controller template view. no matter how try put data in view file, cannot access data i'm passing template.
i've uploaded test module here https://github.com/svenanders/twiglytest
controller:
<?php namespace twigly\controller; use zend\mvc\controller\abstractactioncontroller; use zend\view\model\viewmodel; class twiglycontroller extends abstractactioncontroller { public function twiglyaction() { echo "go..."; // return array('version'=> \zend\version\version::version); return new viewmodel(array( 'data' => array("test"=>"test2"), )); } }
view:
{% in data %} <h2>{{ }}1</h2> {% endfor %} ...done
result:
go... ...done
whereas expected receive data between go... , ...done
a bit of shot in dark but, can try 1 of following in view?
{% key,a in data %} <h2>{{ }}1</h2> {% endfor %} ...done
or
{{ data['test'] }}.
Comments
Post a Comment