codecamp

变量调试

输出某个变量是开发过程中经常会用到的调试方法,除了使用php内置的var_dump和print_r之外,ThinkPHP框架内置了一个对浏览器友好的dump方法,用于输出变量的信息到浏览器查看。

用法:

dump($var, $echo=true, $label=null, $strict=true)

相关参数的使用如下:

参数 描述
var(必须) 要输出的变量,支持所有变量类型
echo(可选) 是否直接输出,默认为true,如果为false则返回但不输出
label(可选) 变量输出的label标识,默认为空
strict(可选) 输出变量类型,默认为true,如果为false则采用print_r输出

如果echo参数为false 则返回要输出的字符串

使用示例:

 $Blog = D("Blog");
 $blog = $Blog->find(3);
 dump($blog);

在浏览器输出的结果是:

array(12) {
   ["id"]            => string(1) "3"
   ["name"]          => string(0) ""
   ["user_id"]       => string(1) "0"
   ["cate_id"]       => string(1) "0"
   ["title"]         => string(4) "test"
   ["content"]       => string(4) "test"
   ["create_time"]   => string(1) "0"
   ["update_time"]   => string(1) "0"
   ["status"]        => string(1) "0"
   ["read_count"]    => string(1) "0"
   ["comment_count"] => string(1) "0"
   ["tags"]          => string(0) ""
}
Trace方法
性能调试
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }