have been using YII2 to do projects, there is in the use of automation configuration, but did not configure themselves. Noon nothing to see the next Yii initialization code, found all PHP just!
YII2 Initializing Project Code
So, we do the project can certainly be done in PHP, so I created a new folder, called AutoConfig, inside the creation of a init, which wrote the following code:
if (!file_exists ('./uploads/')) { if (!mkdir ('./uploads/')) { echo ' fail to make./uploads/file! '; } else{ Echo ' make./uploads/success! '; }}
This is a very simple code to automatically create the Uploads folder, and when the uploads folder does not exist, the Uploads folder is created automatically. We do this under the terminal:
Automatic configuration creation
Open the sibling directory and discover that the Uploads folder has been created. So, if we want to create configuration information, can be directly in the PHP code to configure, and there is no very advanced things.
I'll write another demo2:
Goal:
1. Create the uploads directory at the site root directory
2. Copy the config.php template to the Admin directory from the common directory
3. Generate a Install.lock file in the root directory
4. If the site is initialized, you must delete the root directory install.lock, or you cannot repeat the initialization
Well, let's look at our current directory structure:
Change the init code to read as follows:
<?php//set a long connection so that the visual sees each step execution header ("connection:keep-alive"); Header ("proxy-connection:keep-alive"); set_time_ Limit (0);/* Determine if duplicate initialization of */if (File_exists ('./install.lock ')) { echo ' system has been initialized, and if you want to reinitialize, remove Install.lock '. <br> ";} /* Create uploads folder */if (!file_exists ('./uploads/')) { if (!mkdir ('./uploads/')) { echo ' cannot create uploads folder ' in the root directory '. \ n "; } else{ Echo ' uploads folder created successfully '. ' \ n "; } /* Create/admin/config.php file */if (!file_exists ('./admin/config.php ')) { if (copy ('./common/config.php ', './admin/ Config.php ') { echo ' admin/config.php created successfully! ‘." \ n "; } else{ Echo ' admin/config.php creation failed! ‘." \ n "; }} /* Generate installation Lock install.lock*/ Touch (' Install.lock '), Echo ' configuration is finished, if any configuration fails, manually execute '. ' \ n "; Clearstatcache ();}? >
In terminal execution:
Effect:
Obviously, Admin/config.php has been created, and the uploads directory has been created, as well as Install.lock. PHP Automation configuration is so simple!
I blog original: PHP Web site automation Configuration implementation http://www.wangtuizhijia.com/archives/217
Implementation of automation Configuration for PHP Web site