Cakephp Tutorials
Important Links
CakePHP Configuration.
Basic Configuration :-
Configuration is generally stored in either PHP or INI files.
CakePHP comes with one configuration file by default, but if required you can add additional configuration files and load them in config/bootstrap.php. Cake\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');
Each file loaded after app.php can redefine previously declared values allowing you to customize configuration for development or staging environments.
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.
When changing the namespace in your configuration, you will also need to update your composer.json file to use this namespace as well. Additionally, create a new autoloader by running php composer.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. In a CLI context (from shells) the fullBaseUrl cannot be read from $_SERVER, as there is no webserver involved. You do need to specify it yourself if you do need to generate URLs from a shell (e.g. when sending emails).
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 plugins, templates, locales 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.
Configuration :-
database connections are configured in config/app.php
Sample connection information can be found in config/app.default.php. A sample connection configuration would look like:
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'my_app',
'password' => 'sekret',
'database' => 'my_app',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
]
],
You can define as many connections as you want in your configuration file. You can also define additional connections at runtime using Cake\Datasource\ConnectionManager::config(). An example of that would be:
ConnectionManager::config('default', [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'my_app',
'password' => 'sekret',
'database' => 'my_app',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
]);
Configuration options can also be provided as a DSN string. This is useful when working with environment variables or PaaS providers:
ConnectionManager::config('default', [
'url' => 'mysql://my_app:sekret@localhost/my_app?encoding=utf8&timezone=UTC&cacheMetadata=true',
]);
When using a DSN string you can define any additional parameters/options as query string arguments.