CakePHP Configuration
CakePHP Configuration
When we install CakePHP software in our system, then it provides a predefined config folder, and we can modify it according to our needs in the application. CakePHP provides some configuration.
General Configuration
Here we have listed various elements and their descriptions in CakePHP configuration. In this configuration, we will learn about the component of CakePHP, how they affect your application.
Debug
It Changes the CakePHP debugging output
false = Production mode (when you define debug is false then it will not show any error or warning message)
true = by defining true, it will show an error and warning too.
App.namespace
The namespace element is usually used to find the app class that is defined in the config folder.
App.baseUrl
If you don’t want to use Apache’s mod_rewrite in your Cake PHP application, then you can uncomment it. Don't forget to delete your .htaccess files as well.
App.base
The base directory app resides in the config file and can auto-detect if the base directory is not present. And if you have not provided the correct base, it means that your string starts with a / and does not end with /.
App.encoding
The encoding/format is used to represent your data in the application that generates set characters in designing and encode entities. Besides, it will match all encoding values ??that are specified in your database.
App.webroot
It is the webroot directory.
App.wwwRoot
It shows the file path to the Webroot.
App.fullBaseUrl
It provides the full url path to your application’s root. By default, $_SERVER is used to generate an absolute url in CakePHP. Although you can use it manually to optimize the performance.
App.imageBaseUrl
You can define your image path on the web page under Webroot.
App.cssBaseUrl
You can define your CSS file path on the web path under the Webroot folder.
App.jsBaseUrl
In the folder of Webroot, you can define your js file to the web path.
App.paths
It configured a path that is based on non-class resources such as plugins, location subseries, templates that provide definition paths for plugins, view templates, and locale files.
Security.salt
It uses a random string for hashing. For this purpose, it uses the HMAC salt to provide security to your database value.
Asset.timestamp
It contains a digital record of the last modified file using the asset. timestamp. Also, it records the particular file at the end of the Asset Files URL (CSS, JAVASCRIPT, IMAGE), when appropriate coding values ??are used.
(bool) false – it will not perform any task.
(bool) true – It appends the timestamp interval when debug is true.
(string) ‘force’ – It always adds the timestamp.
Database Configuration
All the connections related to the database can be configured in config / app.php. And this file can be called in Cake \ Datasource \ ConnectionManager to establish the database connection configuration in your application. There is a sample of database connection which is provided in config/app.default.php, and you can see in the given below syntax.
'Datasources' => [ 'default' => [ 'className' => Connection::class, 'driver' => Mysql::class, 'persistent' => false, 'host' => 'localhost', /* * CakePHP will use the default DB port based on the driver selected * MySQL on MAMP uses port 8889, MAMP users will want to uncomment * the following line and set the port accordingly */ //'port' => 'non_standard_port_number', 'username' => 'root', 'password' => '', // if you have not set the password in database then you can left it empty. 'database' => 'cakephp_database', // that is our database name //'encoding' => 'utf8mb4', 'timezone' => 'UTC', 'flags' => [], 'cacheMetadata' => true, 'log' => false, ] ];
When you configure all the database settings in your config/app.php file, then it will show the given below image in your localhost server.
And if you are using mysql for database connection, then you have to define the given below connection in your application.
ConnectionManager :: config(‘default’,[ ‘url’ => ‘mysql://my_pro:secret@localhost/database_name?encoding=utf8 & timezone=UTC &cacheMetadata a=true’, ]);