Search code examples
phppluginszend-framework2view-helpers

how to use forward in view zend 2


I want to write a plugin in ZF2,

An example of the plugin is a like button that shows in every post. It should for example print in PostsAction,

I know I can use:

$like = $this->forward()->dispatch('Application\Controller\Index', array(
    'action' => 'like',
    'postId'   => $Id
));

$like variable returns a button that users can click on. But I want to echo this in the view. In forward the view is not defined.

Also if I use

return $this->getView()->render('application/index/like', array('postId' => $Id));

I don't have access to postId in likeController, because it is set in the view. How I can implement these type of plugins that need a dynamic variables?


Solution

  • I found it ,developed by Mohammad Rostami,Special thanks to him : Plugin In ZF2