最新消息:文章中包含代码时,请遵守代码高亮规范!

opencart Request类详解【原创】

PHP Jason 2041浏览 0评论

OpenCart请求数据封装成了一个类Request!

下面是Request类的代码

class Request {
   public $get = array();
   public $post = array();
   public $cookie = array();
   public $files = array();
   public $server = array();

   public function __construct() {//构造方法
      $_GET = $this->clean($_GET);
      $_POST = $this->clean($_POST);
      $_REQUEST = $this->clean($_REQUEST);
      $_COOKIE = $this->clean($_COOKIE);
      $_FILES = $this->clean($_FILES);
      $_SERVER = $this->clean($_SERVER);

      $this->get = $_GET;
      $this->post = $_POST;
      $this->request = $_REQUEST;
      $this->cookie = $_COOKIE;
      $this->files = $_FILES;
      $this->server = $_SERVER;
   }

   public function clean($data) {//方法转义特殊字符
      if (is_array($data)) {
         foreach ($data as $key => $value) {
            unset($data[$key]);
            $data[$this->clean($key)] = $this->clean($value);
         }
      } else {
         $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
      }
      return $data;
   }
}

代码说明

当你实例化这个类的时候!执行构造方法!把请求数据经过递归方法转义最后放到属性里面

 

实例

$request = new Request();</pre>
$request->get;

这样就可以使用GET传过来的参数了

转载时请注明出处及相应链接,本文永久地址:http://blog.it985.com/9497.html


pay_weixin
pay_weixin
微信打赏
pay_weixin
支付宝打赏
感谢您对作者houjushang的打赏,我们会更加努力!    如果您想成为作者,请点我

您必须 登录 才能发表评论!