How can I use ZF1 $this->action in ZF2?

末鹿安然 提交于 2019-12-01 01:33:43
AlloVince

First you need to write a custom helper like this:

https://github.com/AlloVince/eva-engine/blob/master/vendor/Eva/View/Helper/Action.php

Maybe you need to change the namespace to fit your project, Then register this helper as a invokable helper service in your module config file:

'view_helpers' => array(
    'invokables' => array(
        'action' => 'Eva\View\Helper\Action',
    ),  
),

Then you could call any controller action in view like this:

$this->action('Engine\Controller\PagesController', 'indexAction');

EDIT:

OP found a nice solution here: http://www.michaelgallego.fr/blog/?p=223. Since he didn't post it as an answer, other users might miss it.

Action view helper was not recommended in zf1 and was completely removed in zf2 as bad practice. You should consider changing application design to not rely on such behaviour.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!