Sunday 6 December 2015

CakePhp Configuration

Configuration

While conventions remove the need to configure all of CakePHP, you’ll still need to configure a few things like your database credentials.
Additionally, there are optional configuration options that allow you to swap out default values & implementations with ones tailored to your application.




Configuring your Application

Configuration is generally stored in either PHP or INI files, and loaded during the application bootstrap. CakePHP comes with one configuration file by default, but if required you can add additional configuration files and load them in config/bootstrap.phpCake\Core\Configure is used for general configuration, and the adapter based classes provide config() methods to make configuration simple and transparent.

Loading Additional Configuration Files

If your application has many configuration options it can be helpful to split configuration into multiple files. After creating each of the files in your config/ directory you can load them in bootstrap.php:
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;

Configure::config('default', new PhpConfig());
Configure::load('app', 'default', false);
Configure::load('other_config', 'default');
You can also use additional configuration files to provide environment specific overrides. Each file loaded afterapp.php can redefine previously declared values allowing you to customize configuration for development or staging environments.

General Configuration

Below is a description of the variables and how they affect your CakePHP application.
debug
Changes CakePHP debugging output. false = Production mode. No error messages, errors, or warnings shown. true = Errors and warnings shown.
App.namespace
The namespace to find app classes under.
Note
When changing the namespace in your configuration, you will also need to update your composer.jsonfile to use this namespace as well. Additionally, create a new autoloader by running phpcomposer.phar dumpautoload.
App.baseUrl
Un-comment this definition if you don’t plan to use Apache’s mod_rewrite with CakePHP. Don’t forget to remove your .htaccess files too.
App.base
The base directory the app resides in. If false this will be auto detected. If not false, ensure your string starts with a /and does NOT end with a /. E.g., /basedir is a valid App.base. Otherwise, the AuthComponent will not work properly.
App.encoding
Define what encoding your application uses. This encoding is used to generate the charset in the layout, and encode entities. It should match the encoding values specified for your database.
App.webroot
The webroot directory.
App.wwwRoot
The file path to webroot.
App.fullBaseUrl
The fully qualified domain name (including protocol) to your application’s root. This is used when generating absolute URLs. By default this value is generated using the $_SERVER environment. However, you should define it manually to optimize performance or if you are concerned about people manipulating the Host header.
App.imageBaseUrl
Web path to the public images directory under webroot. If you are using a CDN you should set this value to the CDN’s location.
App.cssBaseUrl
Web path to the public css directory under webroot. If you are using a CDN you should set this value to the CDN’s location.
App.jsBaseUrl
Web path to the public js directory under webroot. If you are using a CDN you should set this value to the CDN’s location.
App.paths
Configure paths for non class based resources. Supports the pluginstemplateslocales subkeys, which allow the definition of paths for plugins, view templates and locale files respectively.
Security.salt
A random string used in hashing. This value is also used as the HMAC salt when doing symetric encryption.
Asset.timestamp
Appends a timestamp which is last modified time of the particular file at the end of asset files URLs (CSS, JavaScript, Image) when using proper helpers. Valid values:
  • (bool) false - Doesn’t do anything (default)
  • (bool) true - Appends the timestamp when debug is true
  • (string) ‘force’ - Always appends the timestamp.

No comments:

Post a Comment