PHP yii 新项目 注意事项

新建项目 composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
目录:

1.config/web.php 修改

1.1 log 用于打印输出
1.2 urlManager

1.config/web.php 修改


#### 1.1 log 用于打印输出
使用方法:Yii::log('your message', 'error', 'orders');
yii::trace("$msg",'$category')
yii::error($msg,$category)
'log' => [
                'traceLevel' => 0, //YII_DEBUG ? 3 : 0,
                'flushInterval' => 1,   //
                'targets' => [
                    [

                        'class' => 'yii\log\FileTarget',
                        'levels' => ['error', 'warning'],
                        'exportInterval' => 1,
                        'logFile' => '@app/runtime/logs/bb.log',
                        /*
                        'logFile' => '@app/runtime/logs/bb.log',
                        'exportInterval' => 100,
                        'class' => 'yii\log\FileTarget',
                        //'levels' => ['error', 'warning'],
                        'categories' => [
                            'yii\db\*',
                            'yii\web\HttpException:*',
                        ],
                        'except' => [
                            'yii\web\HttpException:404',
                        ],
                        */
                    ],
                     [
                        'class' => 'yii\log\FileTarget',
                        'categories' => ['lucky'],
                        'levels' => ['error'],
                        'logVars' => [],   //!!! disable global variables
                        'logFile' => '@app/runtime/logs/lucky-error.log',
                    ],
                    [
                       'class' => 'yii\log\FileTarget',
                       'categories' => ['lucky'],
                       'levels' => ['warning'],
                       'logVars' => [],   //!!! disable global variables
                       'logFile' => '@app/runtime/logs/lucky-warning.log',
                   ],
                    [
                       'class' => 'yii\log\FileTarget',
                       'categories' => ['lucky'],
                       'levels' => ['trace'],
                       'logVars' => [],   //!!! disable global variables
                       'logFile' => '@app/runtime/logs/lucky-trace.log',
                   ],
                    [
                       'class' => 'yii\log\FileTarget',
                       'categories' => ['money'],
                       'levels' => ['info'],
                       'logVars' => [],   //!!! disable global variables
                       'logFile' => '@app/runtime/logs/money.log',
                   ],
                    [
                        'class' => 'yii\log\FileTarget',
                        'categories' => ['promotion'],
                        'levels' => ['error', 'warning','trace'],
                        'logVars' => [],   //!!! disable global variables
                        'logFile' => '@app/runtime/logs/promotion-data.log',
                    ],
                    [
                        'class' => 'yii\log\FileTarget',
                        'categories' => ['agent'],
                        'levels' => ['error', 'warning','trace'],
                        'logVars' => [],   //!!! disable global variables
                        'logFile' => '@app/runtime/logs/agent-data.log',
                    ],
                ],
            ],

1.2 urlManager

urlManager 用于管理 控制器路由访问方式 不添加下面语句
访问方式 http://localhost:8887/index.php?r=site/about
访问方式 http://localhost:8887/site/about

    'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'showScriptName' => false,
        'enablePrettyUrl' => true,
        'enableStrictParsing' => false,
        'rules' => [
            ['class' => 'yii\rest\UrlRule', 'controller' => 'authapi'],
    
        ],
    ],
  1. faker 生成假数据
    config\console.php 中添加一条配置信息
  2. config\console.php 中添加一条配置信息
    'controllerMap' => [ 'fixture' => [ 'class' => 'yii\faker\FixtureController', ],],

注意顶部,定义test测试目录的位置的代码。
Yii::setAlias('@tests', dirname(DIR) . '/tests');

你可能感兴趣的:(PHP yii 新项目 注意事项)