ThinkPHP6.0 configuration



ThinkPHP6 configuration

  • You can add custom configuration files

├─config (configuration directory)

│ ├─app.php │ Application configuration

│ ├─cache.php │ Cache configuration

│ ├─console. php Console configuration

│ ├─cookie.php Cookie configuration

│ ├─database.php Database configuration

│ ├─filesystem.php File disk configuration

│ ├─lang.php │ Multi-language configuration

│ ├─log.php │ Log configuration

│ ├─middleware.php Middleware configuration

│ ├─ route.php URL and routing configuration

│ ├─session.php Session configuration

│ ├─trace.php Trace configuration

│ ├─view.php View configuration

│ └─ ...                   More configuration files

1. General configuration

Template configuration view.php

return [
    // 模板引擎类型使用Think
    'type'          => 'Think',
    // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
    'auto_rule'     => 1,
    // 模板目录名
    'view_dir_name' => 'view',
    // 模板后缀
    'view_suffix'   => 'html',
    // 模板文件名分隔符
    'view_depr'     => DIRECTORY_SEPARATOR,
    // 模板引擎普通标签开始标记
    'tpl_begin'     => '{',
    // 模板引擎普通标签结束标记
    'tpl_end'       => '}',
    // 标签库标签开始标记
    'taglib_begin'  => '{',
    // 标签库标签结束标记
    'taglib_end'    => '}',
];
  • Template suffix, try changing it to php

  • Try changing the tags of ordinary tags and XML tags

2. env environment variable definition

1. Configure env

The root directory after default installation has a .example.env environment variable example file, you can directly change it to .envModify after the file

APP_DEBUG = true


##[APP]

DEFAULT_TIMEZONE = Asia/Shanghai


[DATABASE]

TYPE = mysql

HOSTNAME = 127.0.0.1

DATABASE = test

USERNAME = username

PASSWORD = password

HOSTPORT = 3306

CHARSET = utf8

DEBUG = true


[LANG]

default_lang = zh-cn

2. Call env

  • To use Env, you must first introduce it

    think\facade\Env Facade class

  • Environment variable acquisition is not case-sensitive

Database configuration database.php

use think\facade\Env;

return [

// Default database connection configuration

'default' => Env::get('database.driver', 'mysql'),


## // Custom time query rules

'time_query_rule' => [],


// Automatically write the timestamp field

// true to automatically identify the type, false to turn off

// Character String explicitly specifies the time field type to support int timestamp datetime date

'auto_timestamp' => true,


## // The default time format after the time field is taken out

'datetime_format' => 'Y-m-d H:i:s',


// Database connection configuration information

'connections' => [

'mysql' => [

                                                                                                                                                                                                   Server address

'Hostname' = & GT; ENV :: get ('database.hostname', '127.0.0.1'),

// Database name

'database ' => Env::get('database.database', 'php'),

// Username

'username' => Env::get('database. username', 'root'),

                                                                                                                                                                                                                                                     . // Port

'HOSTPORT' = & GT; ENV :: get ('database.hostport', '3306'),

##// Database connection parameters

'params '= & Gt; [],

// The database encoding uses UTF8

# charset' = & gt :: get ('database.charset', 'UTF8'),

// database table prefix

## 'prefix' = & gt; env :: get ('database.prefix', ''),


############################################### #// Database deployment method: 0 concentrated formula (single server), 1 distributed type (main server) ###### 'deploy' = & gt; 0, ##### // Whether the database read and write is separated Master-slave type is valid######                                                                                                                                                                                                                            

// After reading and writing, the number of main servers after reading and writing

'master_num' = & gt; 1,

## // Specify the server serial number

'slave_no' = & gt; '',

// Whether the field is strictly check whether the field exists

'Fields_Strict' = & GT; TRUE,

## // #'Break_Reconnect' = & GT; FALSE,

## // Monitor SQL

## 'Trigger_SQL' = & GT,

## // Open the field cache

'fields_cache' => false,

'schema' . DIRECTORY_SEPARATOR,

'schema_cache_path' => app()->getRuntimePath() .

],

## // More database configuration information

],

];


##