Maison  >  Article  >  développement back-end  >  yii2 assets 修改

yii2 assets 修改

WBOY
WBOYoriginal
2016-07-29 09:05:581596parcourir

为了强迫大家把静态资源文件从Git仓库里去掉,于是我把nginx的静态资源的配置都干掉了。

但是也影响了大家在开发机上调试这些文件。

考虑到不同机器每次的assets下的module目录都不一样,翻了yii2源码,找到了以下语句。

发现其算法是:$path = (is_file($path) ? dirname($path) : $path) . filemtime($path);

每次都会找到 filemtime来辅助加密。于是想着先把它去掉。这样每次加密后的路径都是都固定的。这样方便把文件放到cdn。且多台机器的时候,这些路径也都是一致的也不会有影响。


    /**
     * Generate a CRC32 hash for the directory path. Collisions are higher
     * than MD5 but generates a much smaller hash string.
     * @param string $path string to be hashed.
     * @return string hashed string.
     */
    protected function hash($path)
    {
        if (is_callable($this->hashCallback)) {
            return call_user_func($this->hashCallback, $path);
        }
        $path = (is_file($path) ? dirname($path) : $path) . filemtime($path);
        return sprintf('%x', crc32($path . Yii::getVersion()));

    }

 文件存放在:vendor/yiisoft/yii2/web/AssetManager.php 

以上就介绍了yii2 assets 修改,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn