/ yii2

yii2-console

使用 Yii2 Console Application

  • 推送链接到百度。

asset

生成 asset 配置文件:

./yii asset/template ./frontend/assets.php

Yii默认使用Closure Compiler来合并JavaScript文件, 使用YUI Compressor来合并CSS文件, 你应手工安装这些工具或修改选项使用你喜欢的工具。

由于closuer编译器和YUI编译器都是java实现的,所有需要先安装JDK

通过composer来下载安装closuer编译器和YUI编译器:

composer require "nervo/yuicompressor" --dev
composer require "crisu83/closurecompiler-bin" --dev

修改配置文件:

  • 修改 jsCompressor 中 compiler.jar 的实际文件
  • 修改 cssCompressor 中 yuicompressor.jar 的实际文件
  • 重新定义 @webroot
// In the console environment, some path aliases may not exist. Please define these:
Yii::setAlias('@webroot', __DIR__ . '/web');
Yii::setAlias('@web', '/');

return [
    // Adjust command/callback for JavaScript files compressing:
    'jsCompressor' => 'java -jar vendor/crisu83/closurecompiler-bin/build/compiler.jar --js {from} --js_output_file {to}',
    // Adjust command/callback for CSS files compressing:
    'cssCompressor' => 'java -jar vendor/nervo/yuicompressor/yuicompressor.jar --type css {from} -o {to}',
    // Whether to delete asset source after compression:
    'deleteSource' => false,
    // The list of asset bundles to compress:
    'bundles' => [
        'frontend\assets\AppAsset',
        'yii\web\YiiAsset',
        'yii\web\JqueryAsset',
    ],
    // Asset bundle for compression output:
    'targets' => [
        'all' => [
            'class' => 'yii\web\AssetBundle',
            'basePath' => '@webroot/assets',
            'baseUrl' => '@web/assets',
            'js' => 'js/all-{hash}.js',
            'css' => 'css/all-{hash}.css',
        ],
    ],
    // Asset manager configuration:
    'assetManager' => [
        'basePath' => '@webroot/assets',
        'baseUrl' => '@web/assets',
    ],
];

实际执行压缩命令时会报错,提示:failed to open stream: No such file or directory',所以需要我们手动创建文件夹:

mkdir ./frontend/web/assets/js
mkdir ./frontend/web/assets/css

执行压缩命令:

./yii asset/compress ./frontend/assets.php ./frontend/config/assets-prod.php

命颜
https://segmentfault.com/a/1190000013364677

cache

刷新架构缓存

一个新的控制台命令添加了,允许您刷新架构缓存。这在更改生产服务器的代码部署导致DB模式是非常有用的。只需运行命令,如下所示:

./yii cache/flush-schema