zoukankan      html  css  js  c++  java
  • phalcon——HTTP 请求

    (一般在控制器方法中使用)

    获取值:

    (1)直接获取值:

         $customerName = $this->request->getPost("name");

    2)自动添加过滤器:

         $email = $this->request->getPost("user_email", "email");

    3)手动添加过滤器:

         $filter = new Filter();

         $email  = $filter->sanitize($this->request->getPost("user_email"), "email");

    4)若值为空,设置默认值

         $email = $this->request->getPost("user_email", "email", "some@example.com");

    使用请求头信息:

    (1)获取服务器IP地址:

         $ipAddress  =  $this->request->getServerAddress();

    (2)获取客户端IP地址:

         $ipAddress  =  $this->request->getClientAddress();

    文件上传:

    use PhalconMvcController;

    class PostsController extends Controller

    {

        public function uploadAction()

        {

            // Check if the user has uploaded files

            if ($this->request->hasFiles()) {

                // Print the real file names and sizes

                foreach ($this->request->getUploadedFiles() as $file) {

                    // Print file details

                    echo $file->getName(), " ", $file->getSize(), " ";

                    // Move the file into the application

                    $file->moveTo('files/' . $file->getName());

                }

            }

        }

    }

  • 相关阅读:
    大话领域驱动
    c#之循环效率
    编程思想之——"人是活的,程序是死的"
    C#之系统异常处理机制
    EF操作扩展之async
    C#提供APP接口之JSON差异
    EF操作MySql
    WCF 消息压缩性能问题及解决方法
    [NoSQL]-Elasticsearch 7.9
    [Linux]-Debian10基础使用
  • 原文地址:https://www.cnblogs.com/wujuntian/p/4695433.html
Copyright © 2011-2022 走看看