如何在 ZF2 中使用 ZF1 $this->action? [英] How can I use ZF1 $this->action in ZF2?

查看:26
本文介绍了如何在 ZF2 中使用 ZF1 $this->action?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是在 ZF2 中缺少 Action View Helper.
例如,我如何在 layout.phtml(或其他视图)中使用?

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?

问题解决了!!!;)http://www.michaelgallego.fr/blog/?p=223>

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

推荐答案

首先你需要像这样编写一个自定义的 helper:

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');

<小时>

编辑:

OP 在这里找到了一个不错的解决方案:http://www.michaelgallego.fr/blog/?p=223.由于他没有将其作为答案发布,其他用户可能会错过.

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.

这篇关于如何在 ZF2 中使用 ZF1 $this->action?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆