从Zend Framework 2中的Form获取发布的数据 [英] Get the posted data from Form in Zend Framework 2

查看:55
本文介绍了从Zend Framework 2中的Form获取发布的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Zend Framework的新手,所以要问一个基本问题.我想从表单的一个字段中获取发布的数据,通常我想获取用于调试目的的数据.

Im new to Zend Framework, so asking a basic question. I want to get the posted data, in general from one field in a form, I wanted to get the data for debugging purposes.

例如,我有一个表单,其中包含用户名,年龄等字段.在addAction()的控制器中,我想获取用户名,将其存储在变量中,并将其用于调试目的.我希望我说清楚了.如果我的问题不清楚,请告诉我.

For example I have a form with fields like username, age and so on. In my controller in addAction(), I want to fetch the username, store it in a variable and use it for debugging purposes. I hope I made it clear. In case if my question is unclear then please do let me know.

谢谢

推荐答案

您不太清楚,所以我建议一些解决方案...

You're not very clear so I suggets a few solutions...

如果您需要普通的POST值,则可以使用

If you need the plain POST value, you can access it using

$this->getRequest()->getPost('name');

从控制器的上下文.

如果您需要以前分配的表单中的值,则可以使用

If you need the value from the form which has been assigned previously, you can access it using

$form->get('elementName')->getValue();

但是,如果您使用的是InputFilters,则需要使用

However, if you're using InputFilters, you need to fetch it using

$form->getInputFilter()->getValue('name');

否则,您要检索的值未通过过滤器传递.

Otherwise, the value you're retrieving was not passed through the filters.

这篇关于从Zend Framework 2中的Form获取发布的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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