| 状态 | 草稿 |
|---|---|
| Todo | Write me |
| 官方最后更新时间 | 2008/10/06 16:37 |
这是一个检索当前请求的所有各种信息的辅助函数。
referrer($default = FALSE) 返回 HTTP referrer,或者如何 referrer 不存在返回默认。参数:
$default 默认返回 - 默认为 FALSE实例:
echo request::referrer();
返回结果
http://www.google.com/search?hl=en&q=kohana&btnG=Google+Search
is_ajax() 通过检查 X-Requested-With HTTP request header 来检测但却请求是否是 ajax 请求。
原文:tests if the current request is an AJAX request by checking the X-Requested-With HTTP request header that most popular JS frameworks now set for AJAX calls.
TRUE,否则返回 FALSE。实例:
我们可以使用此方法来检测控制器中的 ajax 请求并关闭视图模板的输出。这样我们就可以返回一个格式化后的 JSON 响应。
if (request::is_ajax()) { $this->template->auto_render = FALSE; // 关闭自动显示 echo json_encode($animals); }
method() 返回当前 HTTP 请求的方法(GET,POST,PUT,DELETE for example)
实例:
echo request::method();
返回结果:
get
accepts($type = NULL, $explicit_check = FALSE) 返回检测客户端接受的内容类型(content type)的布尔型。参数:
$type 内容类型(content type)$explicit_check 设置为 TRUE 即关闭自然检测 - 默认为 FALSETRUE 如果客户端接受的内容类型通过。否则返回 FALSE实例:
if (request::accepts('xhtml') && request::accepts('xml') && request::accepts('rss') && request::accepts('atom')) { echo '客户端接受了所有内容类型'; } else { echo '客户端不能接受 xhtml,xml,rss,atom 的其中一种或多种内容类型'; }
返回结果:
客户端接受了所有内容类型
preferred_accept($types, $explicit_check = FALSE) compare the q values for given array of content types and return the one with the highest value. If items are found to have the same q value, the first one encountered in the given array wins. If all items in the given array have a q value of 0, FALSE is returned.
$types array of the content types$explicit_check sets to TRUE to disable wildcard checking - default FALSEFALSE if none of the given types are accepted实例:
echo request::preferred_accept(array('xhtml', 'xml'));
返回结果:
xhtml
accepts_at_quality($type = NULL, $explicit_check = FALSE) 返回检测客户端接受的内容类型(content type)的 quality factor。
TRUE 即关闭自然检测 - 默认为 FALSE实例:
echo request::accepts_at_quality('image/jpg');
返回结果:
0.8