ThinkPHP5 configures different database information according to different modules

        Recently, I took over a mall specializing in the sale of medicines in India. The website needs both Chinese and English versions. According to the previous habit, a data table for storing language is often added in the database. When adding data in the background, all text fields, all in Chinese and English, are added and modified as two fields. However, because these two projects were handed over to newcomers to the company, we tried to divide the websites corresponding to the two languages ​​into different modules in one framework, and the data information corresponding to Chinese and English was also stored in a separate database. Record summary here.

        The framework uses ThinkPHP5, and the database configuration file is the database.php file under Application, which is also the database configuration file called by the system by default. If different modules in Chinese and English call different database configuration files, you need to copy the database.php file to each module folder, and then modify the configuration information.

        For example, there are home folder and ehome folder under Application respectively. The home module corresponds to the Chinese database test, and the ehome module corresponds to the English database etest. Then configure the test database in database.php under Application, copy database.php to the ehome folder, and then change the database of the configuration file to etest. If it is a database under a different server, you can also change the configuration file.

        ps: When the website changes the state of Chinese and English, it stores a cookie value, judges the language in the basic controller, and then jumps to the corresponding module to execute the statement. Generally in this case, the function codes of the two modules in Chinese and English are exactly the same, and only the database and the template called are different. First make the Chinese station, then copy the modules of the Chinese station, and change it.

    

         

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325851787&siteId=291194637