Relevant configuration files and read configuration of thinkPHP5.0 framework

1. The format of the configuration file

    a) ThinkPHP supports configuration formats in multiple formats, but they are all parsed into PHP arrays in the end.

    b) The main learning form is the array
        return [
            'name'=>'',
            'age'=>'',
        ];

2. Configuration form

1. Conventional configuration

        a. Conventional configuration directory
                         C:\AppServ\www\tp5\thinkphp\convention.php

        b. Note:
                         generally do not modify the custom configuration

2. Application Configuration

        a. Application configuration directory
                         C:\AppServ\www\tp5\application\config.php

3. Extended configuration
                    a. Extended configuration
                         is actually the management of configuration files in sub-directories

                    b. Extended configuration directory
                         C:\AppServ\www\tp5\application\database.php

                         C:\AppServ\www\tp5\application\extra\Users can customize configuration files

                     c. Read database extension configuration    

                            Read the extension in databse
                                 dump(config('extended file name.password'));
                                 dump(config('database.password'));

                            Read all database extensions
                                  dump(config('database'));

                     d. Custom extension configuration

                            1) Create a new user.php under the extension directory (C:\AppServ\www\tp5\application\extra)

                            2) Open the file    
                                      <?php 
                                          return [
                                                  "name"=>"Xiao Guo",
                                                  "love"=>"Author",
                                                  "wai"=>"Xiao Si"

                                         ];

3. Read custom extension configuration

     dump(config('user'));
                dump(config('user.wai')
                

4. Scene configuration

       a. to solve the problem

            The development process may be developed in different environments

        b. How to use

            1. Modify the application configuration (C:\AppServ\www\tp5\application\config.php)
                'app_status' => 'home',

            2. Create a new one in the application directory (C:\AppServ\www\tp5\application) and create a corresponding home.php

            3. Write relevant configuration in home.php

5. Module configuration

        a. to solve the problem

            Each module has its own unique configuration

        b. How to use it (take the foreground module as an example)

            1. Create a new config.php under the foreground module (C:\AppServ\www\tp5\application\index)

            2. Open the configuration file and write
                <?php 
                return [
                    "index"=>"I am the front-end configuration"
                ];

   
6. Loading order between configuration files

    1. Priority
          Dynamic Configuration > Module Configuration > Scene Configuration > Extended Configuration > Application Configuration > Conventional Configuration
    

    2. Loading sequence
        configuration -> application configuration -> extension configuration -> scene configuration -> module configuration -> dynamic configuration

    3. Configuration file implementation principle
        $data=array(
            "name"=>"conventional configuration",
            'a'=>'a'
            );

        $data1=array(
            "name"=>'Application Configuration',
            "b"=>'b'
            );
         For the configuration loaded later, overwrite the previous loaded configuration with the same name as
        dump(array_merge($data,$data1));
    

Guess you like

Origin blog.csdn.net/qq_43269730/article/details/100022234