Behaviors

Behaviors are instances of yii\base\Behavior, or of a child class. Behaviors, also known as mixins, allow you to enhance the functionality of an existing component class without needing to change the class's inheritance. Attaching a behavior to a component "injects" the behavior's methods and properties into the component, making those methods and properties accessible as if they were defined in the component class itself.
Moreover, a behavior can respond to the events triggered by the component, which allows behaviors to also customize the normal code execution of the component.

这两段话,是Yii2官网上对Bahaviors的定义。先尝试着理解第一段话。

-- 阅读剩余部分 --

const arr = [10,12,15,21];

/**结果:
 * Index: 4, element: undefined
 * Index: 4, element: undefined
 * Index: 4, element: undefined
 * Index: 4, element: undefined
 */
for (var i = 0; i < arr.length; i++){
    setTimeout(function(){
        console.log('Index: ' + i + ', element: ' + arr[i]);
    }, 3000);
}

/**
 * 下面3个,都是正确结果:
 * Index: 0, element: 10
 * Index: 1, element: 12
 * Index: 2, element: 15
 * Index: 3, element: 21
 */
for (var i = 0; i < arr.length; i++){
    setTimeout(function(i2){
        return function(){
            console.log('Index: ' + i2 + ', element: ' + arr[i2]);
        }
    }(i), 3000);
}

for (let i = 0; i < arr.length; i++){
    setTimeout(function(){
        console.log('Index: ' + i + ', element: ' + arr[i]);
    }, 3000);
}

for (var i = 0; i < arr.length; i++){
    (setTimeout(function(j){
        console.log('Index: ' + j + ', element: ' + arr[j]);
    }, 3000))(i);
}

-- 阅读剩余部分 --

yii2-app-basic会经常出现一个bug,就是找不到vendor/bower这个目录,这是由于某种神秘原因,执行composer install的时候,会安装到vendor/bower-asset这个目录下。

具体原因不明。

需要做如下修改:

修改的文件路径是:vendor/yiisoft/yii2/base/Application.php,第461行, 改为bower-asset

-- 阅读剩余部分 --

折腾了2个多小时,已经可以用了,虽然还是有点小问题,但已经可以用了,毕竟我的目的不是折腾这个,而是被迫搭建本地HTTPS来测试geolocation api

网上教程很多,尤其是xampp自带的那个makecert,但我本地死活搞不定,各种报错。后来是用cygwin这个神器解决了。

具体情况如下:

大前提:要把php.ini里的openssl选项给开了。当然,肯定还有其他东西也要开,这个就下......

-- 阅读剩余部分 --