Usually you use the view helper as a proxy for your model for
Create a view helper in the application, for example.
<?php namespace Application\View\Helper; use Zend\View\Helper\AbstractHelper; class MyModelHelper extends AbstractHelper { protected $model; public function __construct($model) { $this->model = $model; } public function myCoolModelMethod() { return $this->model->method(); } }
You can then make it available by registering it with the framework in your Module.php file using the getViewHelperConfig() method and an anomalous function like factory to compose your helper and enter a model that expects
<?php namespace Application; class Module { public function getViewHelperConfig() { return array( 'factories' => array( 'myModelHelper' => function($sm) {
Finally, in your view (any view) you can call your helper, who, in turn, calls the methods of your models.
// view.phtml <?php echo $this->myModelHelper()->myCoolModelMethod(); ?>
Crisp source share