Zend Framework - 需要从视图访问 GET 参数 [英] Zend Framework - need to access a GET parameter from a view

查看:20
本文介绍了Zend Framework - 需要从视图访问 GET 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Zend 框架,我需要的是在我的视图中构建一个 url.通常在常规的 php 代码中,我只是通过使用全局 $_GET 来获取 GET 变量.但是在 Zend 中,我将其设置为清理 URI,因此:

I am using the Zend framework and what I need is to construct a url in my view. Normally in regular php code I'd just grab the GET Variable by using the global $_GET. However with Zend I'm setting it to clean URIs so :

?ac=list&filter=works&page=2

?ac=list&filter=works&page=2

看起来像index/ac/list/filter/works/page/2

Looks like index/ac/list/filter/works/page/2

在我看来,我正在设置一个链接 cs,这样如果 GET 变量过滤器等于工作,那么该链接的颜色就会不同,它会指向同一个页面,只链接如下:

In my view I'm setting a links cs such that if the GET variable filter equals works then the color of that link would be different and it would point to the same page only linked as so:

index/ac/list/filter/extra/page/2

index/ac/list/filter/extra/page/2

同样明智的是,我有许多其他链接,所有这些链接都只有一个 GET 值 - 我该如何设置 - 我正在使用 Zend 框架.

And like wise I have a number of other links all which just one GET value - how do I set this up - I am using the Zend framework.

推荐答案

要直接在视图中访问请求变量,您可以执行以下操作:

To access a request variable direct in the view you could do:

Zend_Controller_Front::getInstance()->getRequest()->getParam('key');

但正如其他人所说,这不是一个好主意.这可能更容易,但请考虑其他选项:

But as others have said, this is not a good idea. It may be easier, but consider other options:

  • 在控制器中设置视图变量
  • 编写一个视图助手,从请求对象中提取变量

这篇关于Zend Framework - 需要从视图访问 GET 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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