zpf 获取表单等数据的用法

2015年4月12日 12:25:35 星期日

有两种方法:

一种是将所有数据合并到一个数组中去

 1     //获得get,post,url中的数据
 2     private function setData()
 3     {
 4         //未做安全验证
 5         $this->data = array_merge($_COOKIE, $_GET, $_POST, $this->route->args);
 6         $this->data = array_map(array($this, ‘getSafeString‘), $this->data);
 7
 8         $this->ispost = count($_POST);
 9     }
10
11     //获取请求数据
12     public function getData($name)
13     {
14         return !empty($this->data[$name]) ? $this->getSafeString($this->data[$name]) : false;
15     }

另一种方式是单个获取

 1     //获取请求数据
 2     public function G($name)
 3     {
 4         if (!$name) {
 5             return array_map(array($this, ‘getSafeString‘), $_GET);
 6         }
 7         return !empty($_GET[$name]) ? $this->getSafeString($_GET[$name]) : false;
 8     }
 9
10     //获取请求数据
11     public function P($name)
12     {
13         if (!$name) {
14             return array_map(array($this, ‘getSafeString‘), $_POST);
15         }
16         return !empty($_POST[$name]) ? $this->getSafeString($_POST[$name]) : false;
17     }
18
19     //获取请求数据
20     public function C($name)
21     {
22         if (!$name) {
23             return array_map(array($this, ‘getSafeString‘), $_COOKIE);
24         }
25         return !empty($_COOKIE[$name]) ? $this->getSafeString($_COOKIE[$name]) : false;
26     }
27
28     //获取请求数据
29     public function S($name)
30     {
31         if (!$name) {
32             return array_map(array($this, ‘getSafeString‘), $_SERVER);
33         }
34         return !empty($_SERVER[$name]) ? $this->getSafeString($_SERVER[$name]) : false;
35     }
36
37     //获取路由中的参数
38     public function R($name)
39     {
40         if (!$name) {
41             return array_map(array($this, ‘getSafeString‘), $this->route->args);
42         }
43         return !empty($this->route->args[$name]) ? $this->getSafeString($this->route->args[$name]) : false;
44     }
45     

传递数据为空的时候, 返回该数组内的所有元素

时间: 2024-08-28 09:37:28

zpf 获取表单等数据的用法的相关文章

在Action中获取表单提交数据

-----------------siwuxie095 在 Action 中获取表单提交数据 1.之前的 Web 阶段是提交表单到 Servlet,在其中使用 Request 对象 的方法获取数据 2.Struts2 是提交表单到 Action,但 Action 没有 Request 对象,不能 直接使用 Request 对象获取数据 「可以间接使用 Request 对象获取数据」 3.Action 获取表单提交数据主要有三种方式: (1)使用 ActionContext 类 (2)使用 Ser

struts2入门之action获取表单提交数据

action获取表单提交数据,有三种方式: 1.根据ActionContext对象获取: 2.利用ServletActionContext类获取表单数据:(其实就是可以获取HttpServletRequest对象) 3.利用接口注入的方式获取表单数据:实现接口(ServletRequestAware) 其实以上三种方式都是action通过操作域对象来获取数据,和servlet中操作域对象有异曲同工之妙, I.通过ActionContext类获取表单提交数据,代码如下: 1 public clas

java 之 servlet如何获取表单的数据

servlet如何获取表单的数据 前端页面通过form表单的形式提交数据 服务端定义servlet接口 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExcption { // 定义一个用户信息类 Users u = new User(); String username; String password; Date birthday;

DataTables获取表单输入框数据

$(document).ready(function() { var table = $('#example').DataTable(); $('button').click(function() { var data = table.$('input, select').serialize(); alert("The following data would have been submitted to the server: \n\n" + data.substr(0, 120)

怎么获取表单数据

import java.io.IOException;import java.io.PrintWriter; import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpS

asp.net MVC中控制器获取表单form提交的数据之实体类数据

第一次写记录文章,难免有不足之处:欢迎指出. 1.新建一个mvc项目如: 2.新建一个Test.cs 注意get,set方法不能简写 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 using System; using System.Collections.Generic; using System.Linq; usi

ubuntu 下CGI c语言 获取form表单的数据

前面文章:使用cgi c 写了一个helloworld 这次 主要使用CGI c语言 获取form表单的数据 1 login.c [email protected]:/usr/lib/cgi-bin$ cat login.c #include<stdio.h> #include<stdlib.h> #include <string.h> int main(){ int i,len=0; char poststr[100]; char m[10],n[10]; char

获取表单提交的数据getParameter()方法

请求对象:request public String getParameter(String name); 通过request的getParameter(String name)方法获取 表单里面的name信息 示列: HTML代码 <input type="text" name="userName"> Jsp代码 Sring userName=equest.getParameter("userName"); request 存储的数

struts2入门之struts2获取表单数据

在上一篇博文中分享了action如何获取表单数据,在本篇博文中分享一下用struts2这个框架如何来获取表单数据. struts2获取表单数据可以分为三种方式: 1.属性封装 2.模型驱动封装 3.表达式封装 分别介绍以上三种方式: 属性封装的步骤:首先在action中定义成员变量,并写set方法(这里为了避免和后面的混淆,把get和set方法都写上得了),然后该action要访问的form表单中的属性值要和定义的成员变量名称一样,在action访问到jsp页面时,form表单中的数据都已经拿到