浅析Yii2中GridView常见操作

1. 是否显示某列

我们举一个简单的案例
条件:有一个get形参数type
需求:仅且type的值等于1的时候,列name才显示,否则该列不显示
代码实现如下:

[
'attribute' => 'name',
'value' => $model->name,
'visible' => intval(Yii::$app->request->get('type')) == 1,
],

继续阅读“浅析Yii2中GridView常见操作”

php 去掉字符串的最后一个字符

原字符串1,2,3,4,5,6,
去掉最后一个字符”,”,最终结果为1,2,3,4,5,6

代码如下:

$str = "1,2,3,4,5,6,"; 
$newstr = substr($str,0,strlen($str)-1); 
echo $newstr; 
//echo 1,2,3,4,5,6

系统自带的函数即可实现这样的效果,两种方法:

//函数1
substr($str, 0, -1)
//函数2
rtrim($str, ",")

Android分享对话框实现,Android7.0之后状态栏着色解决——主题(Theme)的正确玩法

现象

根本原因是BaseActivity基类中,进行了状态栏着色,代码如下: 继续阅读“Android分享对话框实现,Android7.0之后状态栏着色解决——主题(Theme)的正确玩法”

微信、支付宝、手机QQ等自带浏览器环境内左上角返回、关闭按钮事件监控及处理方法

最靠谱的方式是通过JS监控popstate事件,然后进行相应的处理。核心代码如下:

if (window.history && window.history.pushState) {
    //document.addEventListener('visibilitychange', function() {
    //    alert(document.visibilityState);
    //}, false);
    //window.on('popstate', function() {
    //    alert("我监听到了浏览器的popstate");
    //});
    //window.onpopstate = function(e) {
    //    console.log(e.state);
    //
    //};
    $$(window).on('popstate', function() {  // 返回按钮
        var hashLocation = location.hash;   // 获取或设置页面的标签值
        console.log("popstate");
        console.log("hashLocation:"+hashLocation);
        var hashSplit = hashLocation.split("#!/");
        var hashName = hashSplit[1];
        console.log("hashName:"+hashLocation);
        if (hashName !== '') {
            var hash = window.location.hash;    // 获取或设置页面的标签值
            console.log("hash:"+hash);
            if (hash === '') {
                alert('再次点击返回按钮退出程序');
            }
        }
    });
    console.log("pushstate");
    var url = window.location.href;
    var timestamp = new Date().getTime();

    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
        window.history.pushState('forward', null, './#forward');
    } else {
        window.history.pushState('', "大糖医", url+"#"+timestamp); // 状态对象、标题(现在会被忽略),可选的URL地址。
    }
}

继续阅读“微信、支付宝、手机QQ等自带浏览器环境内左上角返回、关闭按钮事件监控及处理方法”