📜 ⬆️ ⬇️

Separation of configurations in Yii by adult

Instead of the preface
I recently engaged in Yii "for production needs." Before that sat on the ZF. Some things in Yii seem inconvenient or inflexible. In particular, the lack of separate configuration and work with the frontend / backend. True AR pleased)). But what am I talking about ?!

Closer to the point
Let's start from the beginning, with a convenient and flexible configuration. Of course, before deciding on the configuration configuration for server and developer, I climbed the forums, looked at what they were writing on Habré ... But all decisions are reduced to determining the host name and decisions based on it about the desired configuration. But thank you, there are testers, there are development teams, there is a lot more then. In general, I do not like the proposed approach. I offer my solution for example ZF. Everything is very simple. I use apache, so the solution is for it. The secret message is to define the server variable APPLICATION_ENV , and everything else is like everywhere else.


')
Index.php file
//   .         .     . //   production defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); //  Yii $yii=dirname(__FILE__).'/../framework/yii.php'; /** *      */ if (APPLICATION_ENV == 'devel') { defined('YII_DEBUG') or define('YII_DEBUG',true); defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3); } //         $config = dirname(__FILE__).'/protected/config/'.APPLICATION_ENV.'.php'; require_once($yii); Yii::createWebApplication($config)->run(); 


configuration file of our site in apache2
 <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName myplace.dev DocumentRoot /home/project/dev/myplace/public #         . SetEnv APPLICATION_ENV "devel" <Directory /home/project/dev/myplace/public/> AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 


For greater convenience, you can use the merge configurations for example

File production.php and devel.php in the configuration folder
 <?php return CMap::mergeArray( //   main.php require(dirname(__FILE__).'/main.php'), array( 'components'=>array( //   db 'db' => array ( //     ), ), ) ); 


This approach will give the necessary configuration flexibility and allow development teams to work comfortably with the same project.

Successes.

Source: https://habr.com/ru/post/146473/


All Articles