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

痴心易碎 提交于 2019-11-30 20:32:09

问题


My problem is that in ZF2 missing Action View Helper.
How can I use for example in layout.phtml (or in other view)?

ZF1: $this->action("index", "index") // call IndexController indexAction

ZF2: ???

How can i solve this?


The problem solved!!! ;) http://www.michaelgallego.fr/blog/?p=223


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12758561/how-can-i-use-zf1-this-action-in-zf2

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