Different environments in CakePHP?

I want to have many conditions in my CakePHP application,

and have a core.php file for each environment, i.e.

core-production.php and core-development.php. How to manage it?

+4
source share
1 answer

If I understand correctly, you want to load different configurations for each location. The best way to handle this is to set up custom configurations based on the location of the server.

To do this, you can create a custom.php configuration that validates the server name.

$domain = strtolower(@$_SERVER['SERVER_NAME']); switch (true) { default: case 'production.domain.com' == $domain: Configure::write('MyDomain.environment', 'production'); break; case 'staging.domain.com' == $domain: Configure::write('MyDomain.environment', 'staging'); break; case 'local.domain.com' == $domain: case 'mybox.com' == $domain: Configure::write('MyDomain.environment', 'local'); break; } 

Now, basically, you can configure the settings based on your environment:

 switch (Configure::read('MyDomain.environment')) { default: // for security; wouldn't want any confusion revealing sensitive information case 'production': Configure::write('debug', 0); break; case 'staging': case 'local': Configure::write('debug', 2); break; } 

Now you can configure everything anywhere using Configure::write('MyDomain.environment', x) without changing the way the CakePHP files read the kernel.

Happy coding!

+3
source

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


All Articles