只要是好东西,都应该主动分享出来,让大家都用起来;鼓励开源,大家一起,为积累更多更好的东西而奋斗!

Smarty插件:HTTP Header(http-header)

http_header(params)点击展开

一、接口功能

能直接在前端smarty模板中设置HTTP Header,包括html、js、json、xml、css等;
另外,如果要在服务器端实现页面跳转,也可通过此插件完成,设置location参数即可
本插件还可以通过设置refresh参数,实现自动刷新
详细参数列表,见参数说明

二、参数说明

/**
 * @param     {Array}  $params      smarty-function的参数列表,具体参数如下:
 *
 * @p-config  {String} location     地址跳转,类似Javascript中的location.href="xxx";此参数优先级最高
 *
 * @p-config  {String} refresh      N秒后自动重定向到url参数指定的页面
 * @p-config  {String} url          需要被自动跳转的地址
 *
 * @p-config  {String} contentType  contentType的简写,默认是:html;可选值有:html,js,javascript,json,xml,css,text
 * @p-config  {String} charset      指定返回内容的字符集,默认是UTF-8;如:UTF-8,GBK等
 */
mark:以上三组参数是互斥的,并且优先级如下:location > refresh > contentType ,使用过程中请注意这一点

三、示例

1、服务器端实现地址跳转(重定向)
                    
                    {%http_header location="/home"%}
                
2、页面显示N秒后自动刷新或重定向
                    
                    {%http_header refresh="5"%}

                    
                    {%http_header refresh="5" url="http://www.baidufe.com"%}
                
3、设置HTTP响应的数据类型以及字符集
                    
                    {%http_header contentType="javascript"%}

                    
                    {%http_header charset="GBK"%}

                    
                    {%http_header contentType="json" charset="UTF-8"%}