CmlPHP在Cml\Http
中内置一些工具方便开发人员处理请求、响应相关的内容;
# Input
\Cml\Http\Input
用来接收用户GET/POST
请求数据
# 获取$_GET string类型数据
\Cml\Http\Input::getString($name, $default = null)
# 获取$_POST string类型数据
\Cml\Http\Input::postString($name, $default = null)
# 获取refer string类型数据
\Cml\Http\Input::referString($name, $default = null)
# 获取$_REQUEST string类型数据
\Cml\Http\Input::requestString($name, $default = null)
# 获取$_GET int类型数据
\Cml\Http\Input::getInt($name, $default = null)
# 获取$_POST int类型数据
\Cml\Http\Input::postInt($name, $default = null)
# 获取refer int类型数据
\Cml\Http\Input::referInt($name, $default = null)
# 获取$_REQUEST int类型数据
\Cml\Http\Input::requestInt($name, $default = null)
# 获取$_GET bool类型数据
\Cml\Http\Input::getBool($name, $default = null)
# 获取$_POST bool类型数据
\Cml\Http\Input::postBool($name, $default = null)
# 获取$_REQUEST bool类型数据
\Cml\Http\Input::requestBool($name, $default = null)
# 获取refer bool类型数据
\Cml\Http\Input::referBool($name, $default = null)
# Request
Cml\Http\Request
用来获取请求的一些信息如用户ip
、是否为移动端发起请求
、是否为ajax请求
等;
# 获取用户IP地址
\Cml\Http\Request::ip()
# 获取用户标识
\Cml\Http\Request::userAgent()
# 获取主机名称
\Cml\Http\Request::host()
# 判断是否为手机浏览器
\Cml\Http\Request::isMobile()
# 判断是否为POST请求
\Cml\Http\Request::isPost()
# 判断是否为GET请求
\Cml\Http\Request::isGet()
# 判断是否为AJAX请求
\Cml\Http\Request::isAjax()
# 判断是否以cli方式运行
\Cml\Http\Request::isCli()
# 获取POST过来的二进制数据,与手机端交互
\Cml\Http\Request::getBinaryData()
# 发起curl请求
\Cml\Http\Request::curl()
# 获取基本地址
\Cml\Http\Request::baseUrl($joinPort = true)
更多方法直接参考api手册
# Cookie
\Cml\Http\Cookie
用来处理Cookie
# 判断Cookie是否存在
\Cml\Http\Cookie::isExist($key);
# 获取某个Cookie值
\Cml\Http\Cookie::get($name);
# 设置某个Cookie值
\Cml\Http\Cookie::set($name, $value, $expire = '',$path = '', $domain = '');
# 删除某个Cookie值
\Cml\Http\Cookie::delete($name);
# 清空Cookie值
\Cml\Http\Cookie::clear($name);
注意
使用\Cml\Http\Cookie
处理cookie的时候默认加密key使用的是配置中auth_key
配置的key。所以如果有使用到\Cml\Http\Cookie
请修改auth_key
配置的key
# Session
Cml\Http\Session
用来处理Session
# 获取session值
\Cml\Http\Session::get($name);
# 设置session值
\Cml\Http\Session::set($key, $value='');
# 删除session值
\Cml\Http\Session::delete($name);
# 清空session
\Cml\Http\Session::clear($name);